lean-log 0.1.0

A tiny, zero-overhead logging framework
Documentation
  • Coverage
  • 11.11%
    3 out of 27 items documented2 out of 12 items with examples
  • Size
  • Source code size: 29.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.21 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • piot

lean-log

A zero-overhead logging framework for Rust with compile-time level filtering, structured logging, and minimal runtime cost.

Add to your project

[dependencies]
lean-log = "0.1"

Usage

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:

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:

Feature Levels compiled in
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:

info!("user logged in"; user_id = 42, %role);   // Display
debug!("parsed value"; ?result);                 // Debug

License

MIT