Code Monkey home page Code Monkey logo

debug-rs's Introduction

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

    debugf!("num: {}, str: {},", 8, "129");
    debugf!("num: {:?}, str: {:?},", 129, "8");
}

Then run with environment variable DEBUG=debug:examples* (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

debug-rs's People

Contributors

zaaack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

yuriylitvin

debug-rs's Issues

DEBUG=debug doesnt work, but DEBUG=* works [bug]

"Then run with environment variable DEBUG=debug (because the examples' package name is still debug):" -> the DEBUG is set and the program doesnt print anything

program:

use debug_rs::debug;

fn main() {
    let x = 123;
    debug!(x, 33, "aaa");

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

Cargo.toml

[package]
name = "ldebug"
version = "0.1.0"
edition = "2021"

[dependencies]
debug-rs = "0.1.3"

output after run

 [.../ldebug]
 git:(main[---UT])
✔️ exit:(code[0])
❱  cargo run -q

.. nothing here.

the DEBUG is set

echo $DEBUG
debug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.