prologger 0.3.0

A production-grade, ergonomic Rust logging library with colored output, file rotation, and structured formatting.
Documentation
# ๐Ÿชต Prologger

[![CI](https://github.com/Jessiejaymz810s/prologger/actions/workflows/ci.yml/badge.svg)](https://github.com/Jessiejaymz810s/prologger/actions/workflows/ci.yml)
[![Crates.io](https://img.shields.io/crates/v/prologger.svg)](https://crates.io/crates/prologger)
[![Docs.rs](https://docs.rs/prologger/badge.svg)](https://docs.rs/prologger)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Rust](https://img.shields.io/badge/rust-1.63%2B-orange.svg)](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

| 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:

```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:

| 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](LICENSE) for details.