# lean-log
A **zero-overhead** logging framework for Rust with compile-time level filtering, structured logging, and minimal runtime cost.
## Add to your project
```toml
[dependencies]
lean-log = "0.1"
```
## Usage
```rust
use lean_log::{info, debug, warn, error, Level};
fn main() {
lean_log::init(); // reads RUST_LOG env var, defaults to Info
info!("server started");
info!("listening on port {}", 8080);
let path = "/api/health";
debug!("request received"; path = path);
warn!("retrying connection"; attempt = 3);
error!("disk full"; used_bytes = 1024_u64);
}
```
Output goes to **stderr** with ANSI colour by default. To write to a file instead:
```rust
lean_log::set_file_logging("app.log").unwrap();
// or append:
lean_log::append_file_logging("app.log").unwrap();
```
## Log levels
`Off` < `Error` < `Warn` < `Notice` < `Info` < `Debug` < `Trace`
Set at runtime with `lean_log::set_level(Level::Debug)` or via the `RUST_LOG` environment variable.
## Compile-time level cap (features)
Enable only the levels you need to eliminate call sites entirely at compile time:
| `max_error` | Error only |
| `max_warn` | Error, Warn |
| `max_notice` | + Notice |
| `max_info` | + Info |
| `max_debug` *(default)* | + Debug |
| `max_trace` | all levels |
| `disabled` | none (all calls removed) |
## Structured fields
Append key=value fields after a `;` separator:
```rust
info!("user logged in"; user_id = 42, %role); // Display
debug!("parsed value"; ?result); // Debug
```
## License
MIT