expand regex and document

This commit is contained in:
Paul Campbell 2024-03-28 14:56:53 +00:00
parent 64970a80bc
commit a48cdccf26

View file

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