Skip to main content

parse

Function parse 

Source
pub fn parse(
    input: &str,
) -> impl Iterator<Item = Result<Fail2BanStructuredLog<'_>, ParseError>> + '_
Expand description

Parse fail2ban log input. Returns a lazy iterator over parse results.

Each line yields Ok(Fail2BanStructuredLog) on success or Err(ParseError) on failure.

ยงExamples

Parse a single line:

โ“˜
let log = parse("2024-01-01 12:00:00,123 fail2ban.filter: INFO [sshd] ...").next();

Parse an entire file, skipping errors:

โ“˜
let content = std::fs::read_to_string("fail2ban.log").unwrap();
for log in parse(&content).flatten() {
    println!("{:?}", log.jail());
}

Collect all errors:

โ“˜
let content = std::fs::read_to_string("fail2ban.log").unwrap();
let (ok, err): (Vec<_>, Vec<_>) = parse(&content).partition(Result::is_ok);