GithubHelp home page GithubHelp logo

thorstenhemann / pino-cloudwatch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dbhowell/pino-cloudwatch

0.0 0.0 1.0 327 KB

AWS CloudWatch Logs transport for pino

License: MIT License

JavaScript 100.00%

pino-cloudwatch's Introduction

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 pinoCloudWatch = require('pino-cloudwatch');
var split = require('split2');
var pump = require('pump');

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

A flushed event is emitted once the logs are successfully pushed / saved in AWS CloudWatch Logs.

note: add the flushed event handler in the stream's events object parameter if your application flow needs to be notified once the logs are successfully pushed

Attach handlers to different stream events:

var pinoCloudWatch = require('pino-cloudwatch');
var streamToCloudWatch = pinoCloudWatch(
    {
        group: 'test'
    },
    {
        flushed: () => {
            // flushed event triggered
        },
        error: (err) => {
            // error event triggered
        },
    });

note: A full list of supported events can be found here https://nodejs.org/dist/v10.19.0/docs/api/stream.html#stream_writable_streams

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

pino-cloudwatch's People

Contributors

dbhowell avatar wojtekmaj avatar oggminator avatar alexneamtu avatar thorstenhemann avatar vahannasibyan avatar bmalaichik avatar dependabot[bot] avatar

Forkers

oggminator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.