Expand description
§rsnx - Rust Nginx Log Parser
A Rust library for parsing nginx access logs, inspired by the Go library gonx.
This library provides functionality to:
- Parse nginx access logs using custom format strings
- Extract log formats from nginx configuration files
- Process log entries with type-safe field access
- Iterate over log files efficiently
§Quick Start
use rsnx::{Reader, Entry};
use std::io::Cursor;
let log_data = r#"127.0.0.1 [08/Nov/2013:13:39:18 +0000] "GET /api/foo HTTP/1.1" 200 612"#;
let format = r#"$remote_addr [$time_local] "$request" $status $body_bytes_sent"#;
let cursor = Cursor::new(log_data);
let reader = Reader::new(cursor, format)?;
for entry in reader {
let entry = entry?;
println!("IP: {}", entry.field("remote_addr")?);
println!("Status: {}", entry.int_field("status")?);
}
§Features
- Format String Parsing: Convert nginx log format strings into regex patterns
- Type-Safe Field Access: Access fields as strings, integers, or floats with proper error handling
- Nginx Config Integration: Extract log formats directly from nginx configuration files
- Iterator Interface: Process log files line by line with Rust’s iterator patterns
- Error Handling: Comprehensive error types using
thiserror
- Optional Serde Support: Serialize/deserialize entries when the
serde
feature is enabled
Re-exports§
pub use entry::Entry;
pub use entry::Fields;
pub use error::Error;
pub use error::Result;
pub use parser::Parser;
pub use reader::Reader;
pub use nginx::NginxReader;