bunyan中的常规(原始)日志如下所示:
$node myapp.js {"name":"myapp","hostname":"myhost","pid":34572,"level":30,"msg":"start","time":"2013-01-04T07:47:25.814Z","v":0} {"name":"myapp","widget_type":"wuzzle","msg":"creating a wuzzle","time":"2013-01-04T07:47:25.815Z","v":0}
可以使用CLI通过管道日志到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)
默认情况下是否可以使用“短”模式,因此节点myapp.js会产生短版本的日志?
@R_301_323@
您可以将自定义原始流传递给bunyan并编写自己的漂亮打印机:
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')
您可以查看完成此工作的this file到pretty-print所有消息.