mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
improve matching
This commit is contained in:
parent
04e391aea1
commit
9413b216ba
24 changed files with 73837 additions and 21689 deletions
|
|
@ -5,6 +5,9 @@ mod server_27;
|
|||
mod server_28;
|
||||
mod server_29;
|
||||
|
||||
pub const MIN_VERSION: u32 = 24;
|
||||
pub const MAX_VERSION: u32 = 29;
|
||||
|
||||
pub fn get_statements(name: &str, version: u32) -> &[crate::LoggingStatement] {
|
||||
match (name, version) {
|
||||
("server", 24) => server_24::STATEMENTS,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
mod data;
|
||||
mod types;
|
||||
|
||||
pub use data::get_statements;
|
||||
pub use data::{get_statements, MAX_VERSION, MIN_VERSION};
|
||||
pub use types::*;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone, Copy)]
|
||||
pub enum LogLevel {
|
||||
Debug,
|
||||
|
|
@ -32,5 +34,36 @@ pub struct LoggingStatement {
|
|||
pub path: &'static str,
|
||||
pub line: usize,
|
||||
pub placeholders: &'static [&'static str],
|
||||
pub has_meaningful_message: bool,
|
||||
pub exception: Option<&'static str>,
|
||||
pub regex: &'static str,
|
||||
}
|
||||
|
||||
impl LoggingStatement {
|
||||
pub fn message(&self) -> impl Display + '_ {
|
||||
LoggingMessage { message: &self }
|
||||
}
|
||||
}
|
||||
|
||||
struct LoggingMessage<'a> {
|
||||
message: &'a LoggingStatement,
|
||||
}
|
||||
|
||||
impl<'a> Display for LoggingMessage<'a> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
if self.message.regex.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut placeholder_index = 0;
|
||||
let regex = &self.message.regex[1..self.message.regex.len() - 1];
|
||||
for part in regex.split("(.*)") {
|
||||
write!(f, "{part}")?;
|
||||
if let Some(placeholder) = self.message.placeholders.get(placeholder_index) {
|
||||
write!(f, "{placeholder}")?;
|
||||
}
|
||||
placeholder_index += 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue