Regular (raw) logs in bunyan looks as following:
$ node myapp.js
{"name":"myapp","hostname":"myhost","pid":34572,"level":30,"msg":"start","time":"2013-01-04T07:47:25.814Z","v":0}
{"name":"myapp","hostname":"myhost","pid":34572,"widget_type":"wuzzle","level":30,"msg":"creating a wuzzle","time":"2013-01-04T07:47:25.815Z","v":0}
It is possible to use the "short" output mode, using the CLI, by piping logs to bunyan -o short
$ node myapp.js | bunyan -o short
07:46:42.707Z INFO myapp: start
07:46:42.709Z INFO myapp: creating a wuzzle (widget_type=wuzzle)
Is it possible to use 'short' mode by default, so node myapp.js
will produce short version of the logs?
You can pass a custom raw stream to bunyan and write your own pretty-printer:
var Logger = require('bunyan')
, Stream = require('stream')
var stream = new Stream()
stream.writable = true
stream.write = function(obj) {
// pretty-printing your message
console.log(obj.msg)
}
var logger = new Logger({
name: 'foo',
streams: [{
type: "raw",
stream: stream,
}],
serializers: {
err: Logger.stdSerializers.err,
req: Logger.stdSerializers.req,
res: Logger.stdSerializers.res,
},
})
// -------------------------------
logger.info('hello world')
You can look at this file that does exactly this job to pretty-print all messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With