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

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

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

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

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

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

- 包体积（解压后）：28.7 kB，5 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10
- 运行依赖：3 个
- 首次发布：2020-02-11T07:35:19.594Z
- 最新版本发布：2024-03-18T23:14:39.203Z
- 近 30 天下载量：409124（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 0 个）

## 中文简介

用于 Winton 日志的 与 Elastic Community Schema 兼容的文件 .

## 安装

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

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

## README

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

# @elastic/ecs-winston-format (英语)

[![npm](https://img.shields.io/npm/v/@elastic/ecs-winston-format.svg)](https://www.npmjs.com/package/@elastic/ecs-winston-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/winstonjs/winston) 与日志兼容 [弹性常见 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) 在一个地方检查所有日志.

`winston` 3.x版本得到支持.

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

## 安装

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

## 使用量

```js
const winston = require('winston');
const { ecsFormat } = require('@elastic/ecs-winston-format');

const logger = winston.createLogger({
  level: 'info',
  format: ecsFormat(/* options */),
  transports: [
    new winston.transports.Console()
  ]
});

logger.info('hi');
logger.error('oops there is a problem', { foo: 'bar' });
```

运行此脚本将生成类似于以下的日志输出 :

```sh
% node examples/basic.js
{"@timestamp":"2021-01-13T21:32:38.095Z","log.level":"info","message":"hi","ecs":{"version":"8.10.0"}}
{"@timestamp":"2021-01-13T21:32:38.096Z","log.level":"error","message":"oops there is a problem","ecs":{"version":"8.10.0"},"foo":"bar"}
```

请看 [ECS Winston 文档](https://www.elastic.co/guide/en/ecs-logging/nodejs/current/winston.html) 为了更多.

## 许可证

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

## 常见问题

### @elastic/ecs-winston-format 是什么？

用于 Winton 日志的 与 Elastic Community Schema 兼容的文件 \.

### 如何安装 @elastic/ecs-winston-format？

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

### @elastic/ecs-winston-format 支持 TypeScript 吗？

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

### @elastic/ecs-winston-format 支持 ESM 还是 CommonJS？

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

### @elastic/ecs-winston-format 需要什么版本的 Node\.js？

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

### @elastic/ecs-winston-format 可以商用吗？

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

### @elastic/ecs-winston-format 的下载量有多少？

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

### @elastic/ecs-winston-format 还在维护吗？

最新版本 1\.5\.3 发布于 2024/03/19（2 年前）；至今共发布 11 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/02/11。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

