@apalchys/pino-cloudwatch

中文文档
0.9.0发布于 2023/11/19MITTypeScriptCommonJS近 30 天下载 2384

CloudWatch Logs transport for pino

原始使用文档
文档目录13 节
  1. About
  2. Usage
  3. Options
  4. group : String (required)
  5. prefix : String
  6. interval : Integer (default 1000 ms, 0 to disable)
  7. aws_access_key_id : String
  8. aws_secret_access_key : String
  9. aws_region : String
  10. Other uses
  11. Writable Stream
  12. Arbitrary logs
  13. Test

pino-cloudwatch

Send pino logs to AWS CloudWatch Logs.

About

pino-cloudwatch is a simple pino transport that buffers and holds pino logs until one of the following conditions are met:

  • the number of logs reaches 10,000
  • the 'size' of the logs reaches 1,048,576 bytes OR
  • there is at least 1 log buffered and 1,000ms (default) has passed without another log item being buffered This is to minimise the number of calls to CloudWatch Logs.

The log group name is specified via the CLI (--prefix) and the log stream name is built based on the following information:

  • An optional prefix,
  • the hostname (via os.hostname()),
  • the process ID (via process.id),
  • the epoch when the first log are sent to CloudWatch Logs

Usage

# ./bin/pino-cloudwatch.js
Sends pino logs to AWS CloudWatch Logs.
Usage: node index.js | pino-cloudwatch [options]

Options:
  --help                   Show help                                   [boolean]
  --version                Show version number                         [boolean]
  --aws_access_key_id      AWS Access Key ID
  --aws_secret_access_key  AWS Secret Access Key
  --aws_region             AWS Region
  --group                  AWS CloudWatch log group name              [required]
  --prefix                 AWS CloudWatch log stream name prefix
  --stream                 AWS CloudWatch log stream name, overrides --prefix option.
  --interval               The maxmimum interval (in ms) before flushing the log
                           queue.                                [default: 1000]

Options

group: String (required)

prefix: String

interval: Integer (default 1000ms, 0 to disable)

The interval is the amount of time in ms that must elapse before attempting to send logs to CloudWatch Logs. Increase this to reduce the number of calls to CloudWatch Logs.

If you set this to 0 then it will only send logs when:

  • It reaches the maxiumum number of logs
  • It reaches the maximum size of the logs

note: Disabling the interval could mean that logs will never be sent to CloudWatch Logs.

aws_access_key_id: String

aws_secret_access_key: String

aws_region: String

Other uses

Writable Stream

This module can be required and used as a writable stream:

var pump = require("pump");
var split = require("split2");
var pinoCloudWatch = require("pino-cloudwatch");

pump(process.stdin, split(), pinoCloudWatch({ group: "test" }));

Writeable Stream Events

Since pino-cloudwatch returns a writable stream, you can attach event handlers like any other writeable stream (see https://nodejs.org/dist/v10.19.0/docs/api/stream.html#stream_writable_streams).

In addition, a flushed event is emitted once the logs are successfully pushed / saved in AWS CloudWatch Logs.

var pump = require("pump");
var split = require("split2");
var pinoCloudWatch = require("pino-cloudwatch");
var streamToCloudWatch = pinoCloudWatch({ group: "test" });

streamToCloudWatch.on("flushed", function () {
  console.log("Logs were successfully sent to AWS CloudWatch");
});

pump(process.stdin, split(), pinoCloudWatch({ group: "test" }));

Arbitrary logs

Technically pino-cloudwatch can send any object mode stream to CloudWatch Logs. This includes any text-based log file. For example: tailing a standard log file like nginx access.log.

Test

# npm test

版本与发布记录

@apalchys/pino-cloudwatch 共发布 11 个版本,首次发布于 2021/11/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.0latest2023/11/192 年前
0.9.0-beta.2beta2023/11/192 年前
0.9.0-beta.12023/11/192 年前
0.9.0-beta.02023/11/192 年前
0.8.62022/01/174 年前
0.8.52022/01/174 年前

关于 @apalchys/pino-cloudwatch 的常见问题

@apalchys/pino-cloudwatch 是什么?

CloudWatch Logs transport for pino

如何安装 @apalchys/pino-cloudwatch?

在项目目录运行 npm install @apalchys/pino-cloudwatch,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 pino-cloudwatch,可以用 npx pino-cloudwatch 直接运行。

@apalchys/pino-cloudwatch 支持 TypeScript 吗?

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

@apalchys/pino-cloudwatch 支持 ESM 还是 CommonJS?

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

@apalchys/pino-cloudwatch 需要什么版本的 Node.js?

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

@apalchys/pino-cloudwatch 可以商用吗?

@apalchys/pino-cloudwatch 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@apalchys/pino-cloudwatch 的下载量有多少?

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

@apalchys/pino-cloudwatch 还在维护吗?

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