dbug 0.0.1

A tiny Rust debugging utility that is heavily inspired by the Node.js debug module
Documentation
  • Coverage
  • 0%
    0 out of 8 items documented0 out of 6 items with examples
  • Size
  • Source code size: 1.67 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • s9tpepper

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