sclog 0.5.0

A fast, simple, dependency-free logging library for Rust.
Documentation
  • Coverage
  • 41.94%
    13 out of 31 items documented3 out of 25 items with examples
  • Size
  • Source code size: 22.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 33s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zhrexx

Simple Customizable Logging

Features

  • super simple
  • dependency-free
  • no_std support (but expects alloc crate)
  • thread-safe
  • panic-safe (crash-safe)
  • fast
  • covers most needs
  • fully customizable
  • flexibility (multiple handlers simultaneously, adjust level at runtime)
  • macro-based
  • automatic source location tracking (file:line)
  • environment variable configuration (SCLOG_LEVEL, std only)
  • chaining for Result and Option with LogUnwrap trait

Usage:

use sclog::{LogLevel, hook_log_handler, log_info, LogUnwrap};


fn main() {
    // 1. Hook your handler
    hook_log_handler(|ll, f, ln, args| println!("{} ({}:{}): {}", ll.as_str().to_lowercase(), f, ln, args));

    // 2. Log messages
    log_info!("Server started on port {}", 8080);
    // Output: [INFO] [main.rs:12] Server started on port 8080

    // 3. Smart unwrapping with location-aware logging
    let result: Result<i32, &str> = Err("database error");
    let val = result.log_unwrap_or(0); // logs error at [main.rs:16] and returns 0

    // 4. Panic/Abort with logging
    log_abort!("Critical failure!");
}