npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pino-aws-cloudwatch

v0.8.0

Published

CloudWatch Logs transport for pino

Downloads

62

Readme

pino-aws-cloudwatch

This is a fork of pino-cloudwatch.

Send pino logs to AWS CloudWatch Logs.

About

pino-aws-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-aws-cloudwatch.js
Sends pino logs to AWS CloudWatch Logs.
Usage: node index.js | pino-aws-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-aws-cloudwatch');

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

Writeable Stream Events

Since pino-aws-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-aws-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-aws-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