@elastic/ecs-morgan-format

中文文档
1.5.1发布于 2023/11/24Apache-2.0TypeScriptCommonJS近 30 天下载 1.7万

与 Elastic Community Schema 兼容的 Morgan 日志的 formatter .

中文使用文档
文档目录3 节
  1. 安装
  2. 使用量
  3. 许可证

@ elastic/ ecs- morgan- format

npm test

这个 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 许可证。 。 。 .

版本与发布记录

@elastic/ecs-morgan-format 共发布 8 个版本,首次发布于 2020/02/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.1latest2023/11/242 年前
1.5.02023/11/013 年前
1.4.02023/10/183 年前
1.1.02021/03/195 年前
1.0.02021/02/095 年前
0.3.02021/01/075 年前

关于 @elastic/ecs-morgan-format 的常见问题

@elastic/ecs-morgan-format 是什么?

与 Elastic Community Schema 兼容的 Morgan 日志的 formatter .

如何安装 @elastic/ecs-morgan-format?

在项目目录运行 npm install @elastic/ecs-morgan-format,或使用 pnpm add / yarn add / bun add。

@elastic/ecs-morgan-format 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elastic/ecs-morgan-format 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@elastic/ecs-morgan-format 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@elastic/ecs-morgan-format 可以商用吗?

@elastic/ecs-morgan-format 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@elastic/ecs-morgan-format 的下载量有多少?

根据 npm 官方下载统计,@elastic/ecs-morgan-format 在 2026/10/13 – 2026/11/11 这 30 天内被下载 16,793 次,日均约 560 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elastic/ecs-morgan-format 还在维护吗?

最新版本 1.5.1 发布于 2023/11/24(2 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/02/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。