# ๐ชต Prologger
[](https://github.com/Jessiejaymz810s/prologger/actions/workflows/ci.yml)
[](https://crates.io/crates/prologger)
[](https://docs.rs/prologger)
[](LICENSE)
[](https://www.rust-lang.org)
A production-grade, ergonomic Rust logging library with colored output, file rotation, and structured formatting.
Prologger implements the [`log`](https://docs.rs/log) crate facade, so you can use the standard `log::info!()`, `log::warn!()`, etc. macros throughout your codebase.
## โจ Features
- **`log` crate compatible** โ Drop-in replacement, works with the entire Rust ecosystem
- **`RUST_LOG` support** โ 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 `log` as a required dependency
## ๐ Quick Start
Add to your `Cargo.toml`:
```toml
[dependencies]
prologger = "0.2"
log = "0.4"
```
Then initialize and start logging:
```rust
use log::{info, warn, error, debug};
fn main() {
prologger::init();
info!("Application started");
debug!("This won't show at default Info level");
warn!("Low disk space");
error!("Connection failed");
}
```
## ๐ Environment Variable Configuration
Control log levels at runtime without code changes:
```rust
fn main() {
prologger::init_from_env(); // reads RUST_LOG
log::info!("Respects RUST_LOG");
}
```
```bash
# Set global level
RUST_LOG=debug cargo run
# Per-module control
RUST_LOG=warn,my_app=debug,hyper=error cargo run
# Silence everything except errors
RUST_LOG=error cargo run
```
You can also use a custom env var:
```rust
use prologger::ProLoggerBuilder;
ProLoggerBuilder::new()
.with_env_var("MY_APP_LOG") // reads MY_APP_LOG instead of RUST_LOG
.with_console_default()
.init()
.unwrap();
```
## ๐ง Builder API
For fine-grained control:
```rust
use log::LevelFilter;
use prologger::ProLoggerBuilder;
ProLoggerBuilder::new()
.with_level(LevelFilter::Debug)
.with_env() // override with RUST_LOG if set
.with_console_default()
.with_module_filter("hyper", LevelFilter::Warn)
.with_module_filter("my_app::db", LevelFilter::Debug)
.init()
.unwrap();
```
## ๐ File Logging with Rotation
```rust
use prologger::{ProLoggerBuilder, RotationConfig};
ProLoggerBuilder::new()
.with_console_default()
.with_rotating_file(
"logs/app.log",
RotationConfig::megabytes(10, 5), // 10MB per file, keep 5 backups
)
.init()
.unwrap();
```
## ๐ JSON Output
Perfect for log aggregation tools (Elasticsearch, Loki, CloudWatch):
```rust
use prologger::{ProLoggerBuilder, FormatterType};
ProLoggerBuilder::new()
.with_formatter(FormatterType::Json)
.with_console_default()
.init()
.unwrap();
```
Output:
```json
{"timestamp":"2026-06-05T20:15:00.123Z","level":"INFO","target":"my_app","message":"Service started on port 8080"}
```
## ๐ฆ Feature Flags
| `color` | โ
| ANSI colored terminal output |
| `file` | โ
| File logging with size-based rotation |
| `json` | โ | JSON structured output formatter |
| `full` | โ | Enables all features |
Enable specific features:
```toml
[dependencies]
prologger = { version = "0.2", features = ["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
```json
{"timestamp":"2026-06-05T20:15:00.123Z","level":"INFO","target":"my_app::api","message":"Request processed successfully"}
```
## โก Performance
Benchmarked with [Criterion](https://github.com/bheisler/criterion.rs) on Linux:
| 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](LICENSE) for details.