An ultra-fast, zero-dependency, and zero-allocation log streaming and analysis library for Rust.
zero-log is designed for performance: zero external crates, zero heap allocations during parsing and streaming, and a small, ergonomic API for both emitting and analyzing logs.
- Zero dependencies — compiles quickly with no external crates.
- Zero-allocation parsing — uses string slices (&str) for parsed fields.
- Streaming processing — single reusable buffer for line-by-line processing of very large log files.
- Pluggable sinks —
LogSinktrait withStdoutSink,FileSinkand testMemorySink. - Lightweight logging macros —
info!,error!,warn!,debug!that accept an optional sink to remain zero-allocation. - Human-readable UTC timestamps —
DTimeprovides formatted date/time strings inYYYY-MM-DD HH:MM:SS(UTC). - Fast analysis utilities —
LogAnalyzer,FileStreamer, andLogStats.
From crates.io (when published):
[dependencies]
zero-log = "0.3.1"or for local development:
[dependencies]
zero-log = { path = "../zero-log" }This crate exposes zero-allocation macros and small helpers for parsing and streaming logs.
Macros default to StdoutSink when no sink is supplied:
use zero_log::{info, error};
fn main() {
info!("server", "Server started");
error!("db", "Connection failed: code {}", 42);
}Pass a mutable sink to the macro to avoid allocating and to control where logs go:
use zero_log::sink::FileSink;
use std::fs::File;
fn main() -> std::io::Result<()> {
let file = File::create("app.log")?;
let mut sink = FileSink::new(file);
info!(&mut sink => "auth", "User {} logged in", 1001);
error!(&mut sink => "net", "Timeout from {}", "10.0.0.1");
Ok(())
}The macro forms:
- info!(target, "fmt", ...)
- info!(&mut sink => target, "fmt", ...)
- same for
error!,warn!,debug!
use zero_log::LogEntry;
fn main() {
let line = "[2026-07-29 14:32:01] [ERROR] [auth] Invalid password attempt";
if let Some(entry) = LogEntry::parse(line) {
assert_eq!(entry.level, "ERROR");
assert_eq!(entry.target, "auth");
println!("{}: {}", entry.timestamp, entry.message);
}
}LogAnalyzer operates on a &str and yields zero-copy LogEntry items:
use zero_log::{LogAnalyzer, LogLevel};
fn main() {
let data = "\
[2026-07-29 14:32:01] [INFO] [server] Started
[2026-07-29 14:32:02] [ERROR] [db] Connection lost
";
let analyzer = LogAnalyzer::new(data);
for err in analyzer.filter_by_level(LogLevel::Error) {
println!("[{}] {}: {}", err.timestamp, err.target, err.message);
}
}FileStreamer::stream iterates lines with a single reusable buffer and calls your closure for each parsed LogEntry:
use zero_log::FileStreamer;
fn main() -> std::io::Result<()> {
FileStreamer::stream("server.log", |entry| {
if entry.level == "ERROR" {
println!("Error in {}: {}", entry.target, entry.message);
}
})?;
Ok(())
}You can also get aggregated statistics:
use zero_log::FileStreamer;
fn main() -> std::io::Result<()> {
let stats = FileStreamer::analyze_file("server.log")?;
println!("Total logs: {}", stats.total_entries);
println!("Errors: {}", stats.error_count);
println!("Warnings: {}", stats.warn_count);
println!("Info: {}", stats.info_count);
println!("Debug: {}", stats.debug_count);
Ok(())
}Expected log line format (used by parser and analyzer):
[timestamp] [LEVEL] [target] message
Example:
[2026-07-29 14:32:01] [ERROR] [auth_service] Invalid password attempt
[2026-07-29 14:32:01] [INFO] [server] Server started successfully
[2026-07-29 14:32:02] [WARN] [db] Connection pool nearly exhausted
Timestamps are emitted by the built-in DTime helper and formatted as YYYY-MM-DD HH:MM:SS in UTC (e.g. [2026-07-29 14:32:01]).
-
LogEntry
LogEntry::parse(&str) -> Option<LogEntry>— zero-copy parser for a single line.
-
LogLevel
- Enum:
Error,Warn,Info,Debug as_str()returns"ERROR" | "WARN" | "INFO" | "DEBUG"
- Enum:
-
LogAnalyzer
LogAnalyzer::new(&str)— build analyzer from log content.entries()— iterator over parsed entries.filter_by_level(LogLevel)— iterator filtered by level.
-
FileStreamer
FileStreamer::stream(path, callback)— stream file lines with a reusable buffer.FileStreamer::analyze_file(path)— returnLogStats.
-
LogStats
total_entries,error_count,warn_count,info_count,debug_count
-
LogSink trait and sinks (
sinkmodule)LogSinktrait:write_log(&mut self, data: &[u8])- Provided sinks:
StdoutSink— writes to stdoutFileSink— writes to astd::fs::FileMemorySink<N>— test-only in-memory sink used by unit tests
-
Macros
info!(...),error!(...),warn!(...),debug!(...)- Forms:
info!(target, "fmt", ...)— uses stdout sinkinfo!(&mut sink => target, "fmt", ...)— uses provided sink
- StackBuffer: small stack-allocated buffer used by logging macros to avoid heap allocations.
event::log_eventwrites formatted lines into the stack buffer and then calls the sink.time_date::DTimeprovides conversion from unix seconds to human-readable date/time without external crates; timestamps are emitted in UTC.
Run unit tests and benches:
cargo test
cargo benchIncluded tests cover:
- Zero-copy parsing
- Macro formatting and zero-allocation behavior
- File streaming and statistics
- StackBuffer overflow safety
- Date/time formatting (DTime)
Contributions welcome:
- Fork the repository
- Create a branch:
git checkout -b feature/your-feature - Commit:
git commit -m "Add feature" - Push:
git push origin feature/your-feature - Open a pull request
Please run tests and keep changes small and focused.
This project is licensed under the MIT License — see LICENSE.
Version: 0.3.0
Language: Rust
Status: Active Development