# @elastic/ecs-morgan-format 中文文档

规范地址：https://npmcn.com/package/%40elastic/ecs-morgan-format/

版本：1\.5\.1
npm 元数据更新时间：2026-09-25T13:38:13.192Z
中文译文更新时间：2026-11-13T10:45:05.814Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40elastic/ecs-morgan-format
原文对照：https://npmcn.com/package/%40elastic/ecs-morgan-format/?lang=original
项目主页：https://github.com/elastic/ecs-logging-nodejs/blob/main/packages/ecs-morgan-format/README.md
源码仓库：https://github.com/elastic/ecs-logging-nodejs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：23.9 kB，5 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10
- 运行依赖：2 个
- 首次发布：2020-02-11T07:35:33.265Z
- 最新版本发布：2023-11-23T19:36:21.993Z
- 近 30 天下载量：16793（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @elastic/ecs-morgan-format
```

也可以使用：`pnpm add @elastic/ecs-morgan-format`、`yarn add @elastic/ecs-morgan-format`、`bun add @elastic/ecs-morgan-format`

## README

![](https://www.elastic.co/static-res/images/elastic-logo-200.png)

# @ elastic/ ecs- morgan- format

[![npm](https://img.shields.io/npm/v/@elastic/ecs-morgan-format.svg)](https://www.npmjs.com/package/@elastic/ecs-morgan-format) [![test](https://github.com/elastic/ecs-logging-nodejs/actions/workflows/test.yml/badge.svg)](https://github.com/elastic/ecs-logging-nodejs/actions/workflows/test.yml)

这个 Node.js 软件包提供了用于 [摩根](https://github.com/expressjs/morgan) 记录兼容的中间软件 [弹性常见 Schema (ECS) 伐木](https://www.elastic.co/guide/en/ecs-logging/overview/master/intro.html)。 。 。 . 结合 [文件节拍](https://www.elastic.co/products/beats/filebeat) 发货人,可以直接将日志发送到弹性搜索和杠杆 [Kibana 日志应用程序](https://www.elastic.co/guide/en/observability/current/monitor-logs.html) 在一个地方检查所有日志.

请看 [Node.js ECS morgan 文档](https://www.elastic.co/guide/en/ecs-logging/nodejs/current/morgan.html)。 。 。 .

## 安装

```sh
npm install @elastic/ecs-morgan-format
```

## 使用量

```js
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/`(将) 生成类似于以下的日志输出:

```sh
% 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 文档](https://www.elastic.co/guide/en/ecs-logging/nodejs/current/morgan.html) 为了更多.

## 许可证

该软件根据 [Apache 2 许可证](https://npmcn.com/package/%40elastic/ecs-morgan-format/LICENSE)。 。 。 .

## 常见问题

### @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 和提交记录判断。

