dbug

Crates.iodbug
lib.rsdbug
version0.0.1
created_at2025-06-18 10:40:55.441614+00
updated_at2025-06-18 10:40:55.441614+00
descriptionA tiny Rust debugging utility that is heavily inspired by the Node.js debug module
homepage
repository
max_upload_size
id1716859
size1,679,773
Omar Gonzalez (s9tpepper)

documentation

README

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");

    // 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");
}

Enable all logs

All logs

Enable only "label" logs

All label logs

Enable all logs that start with "label"

All logs that start with label

Enable all logs except the ones from "label" module

All logs except label

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

All logs except starts with label

Commit count: 0

cargo fmt