Skip to content
/ mydbg Public

Simple wrapper of nodejs debug module with debug levels

License

Notifications You must be signed in to change notification settings

randydu/mydbg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mydbg

Simple wrapper of nodejs debug module with debug level control.

Install

npm install mydbg

Usage

const dbg = require('mydbg')('app');

dbg.info('app starting...');

try {
    ...
}catch(ex){
    dbg.err(ex.message);
}

Levels

There are 5 levels of debug messages supported:

  • trace: detailed messages for development

  • info: generic information messages

  • warn: something abnormal detected, but app can still run

  • err: error detected, but app can still run

  • fatal: error detected, app must terminate

The importance of levels are sorted as following:

trace < info < warn < err < fatal

Output Control

The output of debug messages can be controlled by its level in DEBUG environment variable

DEBUG=app.warn,app.err,app.fatal

or simply use '+' to specify that all messages of the same or high levers are included:

DEBUG=app.warn+

To enable warn messages of all app modules:

DEBUG=*.warn

To enable messages starts from warn level:

DEBUG=*.warn+

To enable messages for multiple moduels:

DEBUG=app.warn+,srv.err+,-ui.*

Please refer to debug module for Wildcards

Methods

  • trace() / info() / warn() / err() / fatal()

They are message output api for each debug level. please refer to debug module for Formatters

const dbg = require('mydbg')('srv');

dbg.trace('server starts');
  • throw_error(message | error)

outputs the message as err level and throw an Error instance.

if(something_bad_detected){
    dbg.throw_error('critial error!');
}

try {
    ...
}catch(ex){
    dbg.throw_error(ex);
}

About

Simple wrapper of nodejs debug module with debug levels

Resources

License

Stars

Watchers

Forks

Packages

No packages published