child.log.info('info');
child.log.debug('debug');
I use the following command:
node app.js | bunyan -o short -l debug
However it only shows INFO. Does not show DEBUG. I'd like ot display debug messages in the console, what am i doing wrong?
child.log.info('info');
child.log.debug('debug');
I use the following command:
node app.js | bunyan -o short -l debug
However it only shows INFO. Does not show DEBUG. I'd like ot display debug messages in the console, what am i doing wrong?
When you create a logger, use the level
option to set the level at which bunyan will emit log messages:
var log = bunyan.createLogger({ level: "debug" });
Similarly, use the level
option to set the level at which child loggers will emit log messages:
var child = log.child({ level: "debug" });
This level
option set at the time of instantiation determines the minimum level of log message emitted by bunyan.
The command line switch -l
( or --level
) is simply a filter; it allows through messages emitted at a given level or above. But, it does not set the minimum level of log message emitted by your instance of bunyan.
For example, suppose I want an instance of bunyan that emits log messages at the "debug"
level or higher. I can put the following in main.js
:
var bunyan = require("bunyan");
var log = bunyan.createLogger({ level: "debug" });
log.trace("Nitty gritty info here.");
log.debug("Eek ork op.");
log.info("The Red Zone is for loading and unloading only.");
If I run the following from the command line:
node main.js | bunyan
I will see this in the output:
Eek ork op.
The Red Zone is for loading and unloading only.
Notice I didn't filter anything from the command line and the call to log.trace()
didn't print anything, either.
Now, type this into the command line:
node main.js | bunyan -l "debug"
You'll get:
Eek ork op.
The Red Zone is for loading and unloading only.
The same as before.
Now, try:
node main.js | bunyan -l "trace"
You'll still get the same output as before.
Why? Because your instance of bunyan is set to emit messages at the "debug"
level or higher. The command-line switch -l
is just a filter.
Finally, try:
node main.js | bunyan -l "info"
This time, you'll only see:
The Red Zone is for loading and unloading only.
The call to log.debug()
was filtered out.
While creating streams for different log levels, creating a stream for debug like
bunyan.createLogger({
name: <name>,
streams: [{
level : 'debug',
stream : process.stdout
}]
});
Using this all your debugging logs would be streamed to the console.