dbug
A tiny Rust debugging utility that is heavily inspired by the Node.js debug module (https://github.com/debug-js/debug).
Installation
cargo add dbug
Usage
dbug creates a logger instance using the name of your module/function which provides a .log("message") function that prints to stdout with a colorized contxt name. The names allow you to turn on/off different debug output across the application without commenting/uncommenting your log calls.o
Examples
Given the code below:
use std::{thread::sleep, time::Duration};
use dbug::{Logger, dbug};
#[allow(unused)]
#[derive(Debug)]
struct Tester {
thing: String,
}
fn main() {
let debugger = Logger::new("label");
debugger.log("hello world");
debugger.log("hello world 2");
sleep(Duration::from_millis(158));
let tester = Tester {
thing: "is a hand".into(),
};
debugger.log(&format!("hello world 3: {:?}", tester));
dbug!(debugger, "hello world 3.5: {:?}", tester);
debugger.log("hello world 4");
let extended = debugger.extend("extended");
extended.log("extended hello world");
let more_ext = extended.extend("deep");
more_ext.log("more");
let debugger = Logger::new("something");
let log = debugger.to_closure();
log("hello from something");
let ext = debugger.extend("extended_again");
let extended = ext.to_closure();
extended("extended hello world");
}
Enable all logs

Enable only "label" logs

Enable all logs that start with "label"

Enable all logs except the ones from "label" module

Enable all logs except the ones that start with "label" module
