mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
try new log matcher
This commit is contained in:
parent
95e09f0e0c
commit
bd3860d0d3
7 changed files with 8943 additions and 8907 deletions
|
|
@ -3,14 +3,10 @@ use databake::Bake;
|
|||
#[derive(Debug, Default, PartialEq, Clone, Copy, Bake)]
|
||||
#[databake(path = crate)]
|
||||
pub enum LogLevel {
|
||||
Debug,
|
||||
Info,
|
||||
Notice,
|
||||
Warn,
|
||||
Error,
|
||||
Alert,
|
||||
Critical,
|
||||
Emergency,
|
||||
Debug = 0,
|
||||
Info = 1,
|
||||
Warn = 2,
|
||||
Error = 3,
|
||||
Exception,
|
||||
#[default]
|
||||
Unknown,
|
||||
|
|
@ -21,12 +17,12 @@ impl From<crate::LogLevel> for LogLevel {
|
|||
match value {
|
||||
crate::LogLevel::Debug => LogLevel::Debug,
|
||||
crate::LogLevel::Info => LogLevel::Info,
|
||||
crate::LogLevel::Notice => LogLevel::Notice,
|
||||
crate::LogLevel::Notice => LogLevel::Info,
|
||||
crate::LogLevel::Warn => LogLevel::Warn,
|
||||
crate::LogLevel::Error => LogLevel::Error,
|
||||
crate::LogLevel::Alert => LogLevel::Alert,
|
||||
crate::LogLevel::Critical => LogLevel::Critical,
|
||||
crate::LogLevel::Emergency => LogLevel::Emergency,
|
||||
crate::LogLevel::Alert => LogLevel::Error,
|
||||
crate::LogLevel::Critical => LogLevel::Error,
|
||||
crate::LogLevel::Emergency => LogLevel::Error,
|
||||
crate::LogLevel::Exception => LogLevel::Exception,
|
||||
crate::LogLevel::Unknown => LogLevel::Unknown,
|
||||
}
|
||||
|
|
@ -41,23 +37,19 @@ pub struct LoggingStatement<'a> {
|
|||
pub line: usize,
|
||||
pub placeholders: &'a [&'a str],
|
||||
pub exception: Option<&'a str>,
|
||||
pub regex: &'a str,
|
||||
pub pattern: &'a str,
|
||||
}
|
||||
|
||||
fn build_pattern(parts: &[crate::MessagePart]) -> String {
|
||||
let mut pattern = String::with_capacity(128);
|
||||
pattern.push('^');
|
||||
for part in parts {
|
||||
match part {
|
||||
crate::MessagePart::Literal(literal) => {
|
||||
pattern.push_str(®ex_syntax::escape(literal))
|
||||
}
|
||||
crate::MessagePart::Literal(literal) => pattern.push_str(literal.as_str()),
|
||||
crate::MessagePart::PlaceHolder(_placeholder) => {
|
||||
pattern.push_str("(.*)");
|
||||
pattern.push_str("\0");
|
||||
}
|
||||
}
|
||||
}
|
||||
pattern.push('$');
|
||||
pattern
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +69,7 @@ pub fn bake_statement(output: &mut String, statement: &crate::LoggingStatement)
|
|||
line: statement.line,
|
||||
exception: statement.exception.as_deref(),
|
||||
placeholders: &placeholders,
|
||||
regex: &pattern,
|
||||
pattern: &pattern,
|
||||
};
|
||||
output.push_str(&statement.bake(&Default::default()).to_string());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue