node.js - winston-elasticsearch 和自定义列
问题描述
我正在使用 winston-logger 和 winston-elasticsearch 创建日志并将它们推送到 ELK。
const esTransportOpts = {
level: 'debug'
};
const logFormat = winston.format.printf((info) => {
let message = `${dateFormat()}, ${global.sessionId}, ${info.level}, ${info.message}`
message = info.obj ? message + `data:${JSON.stringify(info.obj)},` : message
message = this.log_data ? message + `log_data:${JSON.stringify(this.log_data)},` : message
return message
});
const Logger = new createLogger({
transports: [
new transports.Console({
level: 'silly',
format: combine(
timestamp(),
colorize({level: true}),
consoleFormat
),
}),
new transports.File({
level: 'silly',
format: logFormat,
filename: path.join(__dirname, './uiServiceLog.log'),
maxsize: 2000000,
maxFiles: 20
}),
new Elasticsearch(esTransportOpts),
]
});
我正在以正确的格式获取我的日志文件..
2021-11-15 13:39:20, sessionid, 信息, 我的消息
但我的 ELK 没有获得 sessionid .. Elasticsearch DEBUG: 2021-11-15T20:20:35Z
starting request {
"method": "POST",
"bulkBody": true,
"path": "/_bulk",
"body": [
{
"index": {
"_index": "logs-2021.11.15",
"_type": "_doc",
"pipeline": null
}
},
{
"@timestamp": "2021-11-15T20:20:35.457Z",
"message": "\u001b[1m\u001b[31m=============================================\u001b[39m\u001b[22m",
"severity": "info",
"fields": {}
},
{
"index": {
"_index": "logs-2021.11.15",
"_type": "_doc",
"pipeline": null
}
},
{
"@timestamp": "2021-11-15T20:20:35.457Z",
"message": "\",
"severity": "info",
"fields": {}
},
{
"index": {
"_index": "logs-2021.11.15",
"_type": "_doc",
"pipeline": null
}
},
{
"@timestamp": "2021-11-15T20:20:35.458Z",
"message": "\u001b\u001b[22m",
"severity": "info",
"fields": {}
}
],
"query": {
"wait_for_active_shards": "1",
"timeout": "2000ms"
}
}
我尝试使用转换,但它不起作用。无论如何我可以转换 ElK 消息,以便我的日志文件看起来像 ELK 消息。
解决方案
推荐阅读
- mysql - 如何在 SQL 中显示所有已批准状态的总数?
- python - 我的简单添加代码不起作用,我不知道为什么
- flutter - 如何在 Flutter 中过滤流?
- sql-server - 如何防止触发器触发,以免重复数据输入到表中
- google-apps-script - 谷歌脚本比较日期
- javascript - Vue Quasar - 异步数据默认为 [object Object] 的 Qselect
- c# - C# 检查中间件中的响应类型
- javascript - 段落隐藏在前面的相对 div 后面,我如何在下面清除它?
- power-automate - Power Automate Desktop - 创建子流或存储函数库
- discord.py - Discord.py,client.get_all_members() 不起作用