#access #logs #parse

access_log_parser

A library of Rust parsers for reading access logs in a strongly-typed way

6 releases (breaking)

0.6.0 Apr 11, 2021
0.5.0 Aug 4, 2020
0.4.0 Nov 19, 2019
0.3.0 Apr 19, 2019
0.1.0 Apr 17, 2019

#391 in Parser implementations

41 downloads per month

Apache-2.0

67KB
1.5K SLoC

Access Log Parser

This is a pure Rust library for parsing access log entries. It currently support common, combined, Cloud Controller Nginx and Gorouter log formats.

Usage

Add the following to your Cargo.toml:

[dependencies]
access_log_parser = "0.6"

Parse a log line:

    let entry = parse(
        LogType::CommonLog,
        r#"127.0.0.1 - - [15/Mar/2019:03:17:05 +0000] "GET / HTTP/1.1" 200 612"#,
    );
    if let Ok(LogEntry::CommonLog(entry)) = entry {
        assert_eq!(entry.ip, Ipv4Addr::new(127, 0, 0, 1));
        assert!(entry.identd_user.is_none());
        assert!(entry.user.is_none());
        assert_eq!(
            entry.timestamp,
            FixedOffset::west(0).ymd(2019, 3, 15).and_hms(3, 17, 5)
        );
        match entry.request {
            LogFormatValid::Valid(req) => {
                assert_eq!(req.method(), http::Method::GET);
                assert_eq!(req.uri(), "/");
                assert_eq!(req.version(), http::Version::HTTP_11);
                assert_eq!(entry.status_code, http::StatusCode::OK);
                assert_eq!(entry.bytes, 612);
            }
            LogFormatValid::InvalidRequest(path) => panic!("invalid path [{}]", path),
            LogFormatValid::InvalidPath(path, err) => {
                panic!("invalid request [{}], err: {:?}", path, err)
            }
        }
    }

Features

  • Read access log entries, parse them to rust structs and process the data in your programs
  • Supported log formats:
    • Common
    • Combined
    • Cloud Controller Nginx
    • Gorouter

License

This software is released under version 2.0 of the Apache License.

Dependencies

~2.5MB
~39K SLoC

;s`