improve matching

This commit is contained in:
Robin Appelman 2024-07-22 18:57:18 +02:00
commit 9413b216ba
24 changed files with 73837 additions and 21689 deletions

View file

@ -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

View file

@ -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::*;

View file

@ -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(())
}
}