Simple wrapper of nodejs debug module with debug level control.
npm install mydbg
const dbg = require('mydbg')('app');
dbg.info('app starting...');
try {
...
}catch(ex){
dbg.err(ex.message);
}
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
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
- 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);
}