#glob-pattern #dev #development #filename

debug-rs

A debug crate for rust inspired by NodeJS debug module, colored, including crate name, file name and line, filtered by glob patterns

4 releases

Uses old Rust 2015

0.1.3 Aug 9, 2017
0.1.2 Aug 8, 2017
0.1.1 Aug 8, 2017
0.1.0 Aug 8, 2017

#47 in #glob-pattern

MIT license

7KB
81 lines

debug-rs   Build Status Latest Version docs License

A debug crate for rust inspired by NodeJS debug module.

Features

  • colored
  • including crate name, file name and line
  • filtered by glob patterns.

Install

debug-rs = "*"

or using cargo-edit

cargo add debug-rs

Usage

Here is the code in examples folder:

#[macro_use]
extern crate debug_rs;


fn main() {
    debug!(666, 33, "aaa");

    debug!(vec![1, 2, 3]);
}

Then run with environment variable DEBUG=debug (because the examples' package name is still debug):

If environment variable DEBUG is undefined, then it won't print anything.

Windows

Running with env variables in windows shell might be a little different:

DEBUG=*,-not_this cargo run // for *unix
// or
set DEBUG=*,-not_this; cargo run // for windows
// or
$env:DEBUG = "*,-not_this"; cargo run // for PowerShell

DEBUG format

  1. Single glob pattern for <package name>:<file name>: e.g. DEBUG=debug*
  2. Multi glob patterns separated by comma: e.g. DEBUG=debug:examples*,hyper*,
  3. Exclude global patterns by prefix "-": e.g. DEBUG=*,-not_this*

Output format

<package name>:<file name>:L<line number> ...custom variables

Performance

debug_build_only feature can make debug macro won't generate any code in release mode, and default is turn on. you can disable it by config features in Cargo.toml.

Working in release mode:


[dependencies]
debug-rs = { version = "*", default-features=false }

Controlled by features:

[dependencies]
debug-rs = { version = "*", default-features=false, features=["disable"] }

License

MIT

Dependencies

~4–10MB
~118K SLoC