| Crates.io | dbug |
| lib.rs | dbug |
| version | 0.0.1 |
| created_at | 2025-06-18 10:40:55.441614+00 |
| updated_at | 2025-06-18 10:40:55.441614+00 |
| description | A tiny Rust debugging utility that is heavily inspired by the Node.js debug module |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1716859 |
| size | 1,679,773 |
A tiny Rust debugging utility that is heavily inspired by the Node.js debug module (https://github.com/debug-js/debug).
cargo add dbug
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
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");
// Simulate a slow function
sleep(Duration::from_millis(158));
let tester = Tester {
thing: "is a hand".into(),
};
// This should log +158 ms since last log call
debugger.log(&format!("hello world 3: {:?}", tester));
// Use like format! or println!
dbug!(debugger, "hello world 3.5: {:?}", tester);
debugger.log("hello world 4");
// Extend the logger to add more context to the prefix
let extended = debugger.extend("extended");
extended.log("extended hello world");
// Add even more context to prefix
let more_ext = extended.extend("deep");
more_ext.log("more");
// Use as closures
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");
}




