@ elastic/ ecs- morgan- format
这个 Node.js 软件包提供了用于 摩根 记录兼容的中间软件 弹性常见 Schema (ECS) 伐木。 。 。 . 结合 文件节拍 发货人,可以直接将日志发送到弹性搜索和杠杆 Kibana 日志应用程序 在一个地方检查所有日志.
请看 Node.js ECS morgan 文档。 。 。 .
安装
npm install @elastic/ecs-morgan-format
使用量
const app = require('express')()
const morgan = require('morgan')
const { ecsFormat } = require('@elastic/ecs-morgan-format')
app.use(morgan(ecsFormat(/* options */)))
app.get('/', function (req, res) {
res.send('hello, world!')
})
app.listen(3000)
运行此脚本并提出请求( 通过 curl -i localhost:3000/(将)
生成类似于以下的日志输出:
% node examples/express.js | jq . # piping to jq for pretty-printing
{
"@timestamp": "2023-10-16T22:00:33.782Z",
"log.level": "info",
"message": "::ffff:127.0.0.1 - - [16/Oct/2023:22:00:33 +0000] \"GET / HTTP/1.1\" 200 13 \"-\" \"curl/8.1.2\"",
"http": {
"version": "1.1",
"request": {
"method": "GET",
"headers": {
"host": "localhost:3000",
"user-agent": "curl/8.1.2",
"accept": "*/*"
}
},
"response": {
"status_code": 200,
"headers": {
"x-powered-by": "Express",
"content-type": "text/html; charset=utf-8",
"content-length": "13",
"etag": "W/\"d-HwnTDHB9U/PRbFMN1z1wps51lqk\""
},
"body": {
"bytes": 13
}
}
},
"url": {
"path": "/",
"domain": "localhost",
"full": "http://localhost:3000/"
},
"client": {
"address": "::ffff:127.0.0.1",
"ip": "::ffff:127.0.0.1",
"port": 60455
},
"user_agent": {
"original": "curl/8.1.2"
},
"ecs.version": "8.10.0"
}
请看 Node.js ECS morgan 文档 为了更多.
许可证
该软件根据 Apache 2 许可证。 。 。 .