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","hostname":"myhost","pid":34572,"widget_type":"wuzzle","level":30,"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)
默认情况下是否可以使用“短”模式,所以
node myapp.js
将生成日志的短版本? 最佳答案
您可以将自定义原始流传递给bunyan并编写自己的 pretty-print :
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所有消息。
关于node.js - 默认情况下如何在Bunyan中设置 'short'输出模式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20880062/