@log4js2/sns-appender
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

sns-appender

An appender for @log4js2/core that sends log events to an SNS topic to be handled by AWS.

Build Status codecov dependencies

Installation

npm install --save @log4js2/core @log4js2/sns-appender

Configuration

Set up the SNS appender in the configure method.

import {configure, LogLevel} from '@log4js2/core';
import SNSAppender from '@log4js2/sns-appender';

configure({
    layout : '%d [%p] %c - %m %ex',
    appenders : [{
        name: 'sns',
        appender: SNSAppender,
        level: LogLevel.FATAL,
        config: {
            application: 'MyApp', // optional
            protocol: ['email', 'sms'],
            region: 'us-east-1',
            topicArn: 'arn:aws:sns:us-east-1:123456789012:errors'
        }
    }]
});

*Note: it is probably a good idea to only use SNS appending when a high level error occurs, otherwise you can pollute your stream with unimportant logs. Use filters and logging levels to ensure logs only are received when necessary.

Handling the SNS

SNS Subscriptions

The SNSAppender configuration object allows you to configure one or multiple protocols. See the SNS subscribe documentation for which protocols can be used.

Handling raw JSON

The SNS record contains a log field with the log that caused the SNS appender to trigger. It also contains a raw field with the unformatted log event (for easier parsing).

{
  "application": "MyApplication",
  "log": "2019-02-12 12:55:32.000 [INFO] Doing something \n ...",
  "raw": {
    "level": 100,
    "error": "An Unexpected Error",
    "message": "An error occurred",
    ...
  }
}

Contributors

Library built and maintained by Robin Schultz

If you would like to contribute (aka buy me a beer), you can send funds via PayPal at the link below.

paypal

Readme

Keywords

Package Sidebar

Install

npm i @log4js2/sns-appender

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

13.6 kB

Total Files

7

Last publish

Collaborators

  • anigenero