expand regex and document
This commit is contained in:
parent
64970a80bc
commit
a48cdccf26
1 changed files with 27 additions and 5 deletions
32
src/main.rs
32
src/main.rs
|
@ -9,18 +9,40 @@ struct Cli {
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let re = regex::Regex::new(
|
let field_re = r"(.*?)";
|
||||||
r"^(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*?)[\t\s]+(.*)$",
|
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() {
|
for line in read_to_string(cli.input)?.lines() {
|
||||||
if let Some(caps) = re.captures(line) {
|
if let Some(caps) = re.captures(line) {
|
||||||
// println!("{:#?}", &caps);
|
// println!("{:#?}", &caps);
|
||||||
println!(
|
println!(
|
||||||
"{} {:5} {} {} {}",
|
"{} {: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 {
|
} else {
|
||||||
println!("{}", line);
|
println!("XXX {}", line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue