๐ชต Prologger
A production-grade, ergonomic Rust logging library with colored output, file rotation, and structured formatting.
Prologger implements the log crate facade, so you can use the standard log::info!(), log::warn!(), etc. macros throughout your codebase.
โจ Features
logcrate compatible โ Drop-in replacement, works with the entire Rust ecosystemRUST_LOGsupport โ Configure log levels via environment variable- Colored console output โ Level-based ANSI coloring with auto-detection
- Multiple formatters โ Pretty (human), JSON (machine), Compact (minimal)
- File logging โ Write to files with size-based rotation
- Multi-sink โ Route logs to multiple destinations simultaneously
- Builder API โ Fluent configuration with sensible defaults
- Module filtering โ Fine-grained per-module log level control
- Thread-safe โ All components are
Send + Sync - Lightweight โ Only
logas a required dependency
๐ Quick Start
Add to your Cargo.toml:
[]
= "0.2"
= "0.4"
Then initialize and start logging:
use ;
๐ Environment Variable Configuration
Control log levels at runtime without code changes:
# Set global level
RUST_LOG=debug
# Per-module control
RUST_LOG=warn,my_app=debug,hyper=error
# Silence everything except errors
RUST_LOG=error
You can also use a custom env var:
use ProLoggerBuilder;
new
.with_env_var // reads MY_APP_LOG instead of RUST_LOG
.with_console_default
.init
.unwrap;
๐ง Builder API
For fine-grained control:
use LevelFilter;
use ProLoggerBuilder;
new
.with_level
.with_env // override with RUST_LOG if set
.with_console_default
.with_module_filter
.with_module_filter
.init
.unwrap;
๐ File Logging with Rotation
use ;
new
.with_console_default
.with_rotating_file
.init
.unwrap;
๐ JSON Output
Perfect for log aggregation tools (Elasticsearch, Loki, CloudWatch):
use ;
new
.with_formatter
.with_console_default
.init
.unwrap;
Output:
๐ฆ Feature Flags
| Feature | Default | Description |
|---|---|---|
color |
โ | ANSI colored terminal output |
file |
โ | File logging with size-based rotation |
json |
โ | JSON structured output formatter |
full |
โ | Enables all features |
Enable specific features:
[]
= { = "0.2", = ["full"] }
๐จ Output Formats
Pretty (default)
2026-06-05 20:15:00.123 INFO [my_app::api] Request processed successfully
2026-06-05 20:15:00.456 WARN [my_app::db] Connection pool running low
2026-06-05 20:15:00.789 ERROR [my_app::api] Failed to process request
Compact
I: Request processed successfully
W: Connection pool running low
E: Failed to process request
JSON
โก Performance
Benchmarked with Criterion on Linux:
| Operation | Time |
|---|---|
| Compact format | ~159 ns |
| Pretty format | ~693 ns |
| JSON format | ~786 ns |
| Pretty + color | ~1.28 ยตs |
| Filter (global) | ~3.2 ns |
| Filter (module match) | ~309 ns |
| Env parse (simple) | ~52 ns |
| Env parse (complex) | ~511 ns |
Filter rejection costs 3.2 ns โ effectively free. Run benchmarks yourself with cargo bench --all-features.
๐๏ธ Architecture
prologger
โโโ src/
โ โโโ lib.rs # Public API & convenience functions
โ โโโ builder.rs # Builder pattern configuration
โ โโโ logger.rs # log::Log trait implementation
โ โโโ filter.rs # Level filtering engine
โ โโโ env.rs # RUST_LOG environment variable parser
โ โโโ color.rs # ANSI color support
โ โโโ rotation.rs # File rotation logic
โ โโโ formatter/ # Output formatters
โ โ โโโ pretty.rs # Human-readable format
โ โ โโโ json.rs # JSON format
โ โ โโโ compact.rs # Minimal format
โ โโโ sink/ # Output destinations
โ โโโ console.rs # Terminal output
โ โโโ file.rs # File output
โโโ benches/ # Criterion benchmarks
โโโ examples/
โโโ tests/
๐ License
MIT โ see LICENSE for details.