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 an iterator over parse results.

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

When the parallel feature is enabled, all lines are parsed concurrently using Rayon and results are collected upfront. Without it, lines are parsed lazily on demand. The API is identical in both cases.

ยงExamples

Parse a single line:

โ“˜
let log = parse("2024-01-01 12:00:00,123 fail2ban.filter [1] INFO [sshd] Found 1.2.3.4").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);