Crate debug_log

Source
Expand description

Dead simple log utils for debug in Rust.

  • 🦀 Enabled only in debug mode when DEBUG environment variable is set
  • 🔊 Only perform log in files whose paths match DEBUG="filename". Match all by using DEBUG="", or DEBUG="*"
  • 📦 Group output with debug_group
  • 📤 WASM support. It will use the console API.

The output log is super easy to read on VS Code with sticky scroll enabled.

§Example

use debug_log::{debug_dbg, debug_log, group};
group!("A Group");
{
    group!("Sub A Group");
    let arr: Vec<_> = (0..3).collect();
    debug_dbg!(&arr);
    {
        group!("Sub Sub A Group");
        debug_dbg!(&arr);
    }
    debug_log!("Hi");
    debug_dbg!(&arr);
}

{
    group!("B Group");
    debug_log!("END");
}

Run with DEBUG=* cargo run

Output

A Group {
    Sub A Group {
        [src/lib.rs:144] &arr = [
            0,
            1,
            2,
        ]
        Sub Sub A Group {
            [src/lib.rs:147] &arr = [
                0,
                1,
                2,
            ]
        }
        [src/lib.rs:150] Hi
        [src/lib.rs:151] &arr = [
            0,
            1,
            2,
        ]
    }
    B Group {
        [src/lib.rs:157] END
    }
}

Modules§

console

Macros§

debug_dbg
It can be filtered by DEBUG env and can only log on debug mode
debug_log
Use it like println!(). Except it can be filtered by DEBUG env and can only log on debug mode
group
Group the following logs until the guard is dropped

Functions§

set_debug
Change the DEBUG value to filter tests