diff --git a/src/main.rs b/src/main.rs index 3dde4c3..4f867b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,18 +9,40 @@ struct Cli { fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - let re = regex::Regex::new( - r"^(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*)$", - )?; + let field_re = r"(.*?)"; + let message_re = r"(.*)"; + let delimitier_re = r"[\t\s]+"; + let re = regex::Regex::new(&format!( + r"^{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}$", + field_re, // 1 Log Level + delimitier_re, + field_re, // 2 Timestamp + delimitier_re, + field_re, // 3 Version + delimitier_re, + field_re, // 4 Site + delimitier_re, + field_re, // 5 Invocation + delimitier_re, + field_re, // 6 Label 1 + delimitier_re, + field_re, // 7 Label 2 + delimitier_re, + message_re, // 8 Message + ))?; for line in read_to_string(cli.input)?.lines() { if let Some(caps) = re.captures(line) { // println!("{:#?}", &caps); println!( "{} {:5} {} {} {}", - &caps[2], &caps[1], &caps[6], &caps[7], &caps[8] + &caps[2], // timestamp + &caps[1], // log level + &caps[6], // label 1 + &caps[7], // label 2 + &caps[8] // message ); } else { - println!("{}", line); + println!("XXX {}", line); } } Ok(())