我正在使用Bunyan库记录我的Nodejs应用程序。当前正在像下面这样记录
{"name":"testing-log","hostname":"tharindu-Latitude-3490","pid":30189,"level":50,"msg":"subscription - M-98712706666, S_ID-10147, P_ID-1, C-Method-Wallet , ERR-not a valid method","time":"2019-12-18T09:24:03.635Z","v":0}
但是我想使用新字段和如下所示的其他格式来格式化该日志。
{
"correlation-ids": ["aaaaabf-f89a-4ff3-b648-hhuu44jn43b", "bbbbjru778-f89a-fffh-t6y6-848888hhjuj89"], //This parameter should be unique, and logged in each event of a transaction
"timestamp": "2019-11-01T17:39:44.880Z",
"log-name": "test log"
"hostname": "teset log 1",
"app-name": "MMM",
"version": 1.0,
"env": "prod",
"namespace": "com.decoo.mhng",
"thread": "",
"logger": {
"path": "/some/file/path/sample.log",
"type": "bunyan"
}, //These parameters should be able to configure through a single point
"src": {
"file": "/some/file/path/src.js",
"line": 33,
"function": "someFunction"
},
"level": "DEBUG", //(TRACE, DEBUG, INFO, WARNING, ERROR, FATAL)
"message": "Some Message",
"payload": { //Optional
"customVar1": "Hello",
"customVar2": {
"customVar3": "World",
"customVar4": 7
}
},
"tags": [
]
}
我浏览了Bunyan文档,但没有找到格式化它的方法。如果有人可以建议如何像上述示例一样实现日志记录。