Skip to content

Winston Transport for Amazon SNS specialized for JSON logs in Sumo Logic

Notifications You must be signed in to change notification settings

Battlefy/winston-sns-sumo-logic

Repository files navigation

winston-sns-sumo-logic

Circle CI

An Amazon SNS transport for winston 3.x specialized for JSON logs in Sumo Logic.

Sumo Logic is not required to use this package if you only want to send nicely formatted JSON messages to Amazon SNS.

Requires Node.js 10.13.x or greater.

Usage

const {createLogger} = require('winston');
const AWS = require('aws-sdk');
const WinstonSnsSumoLogic = require('winston-sns-sumo-logic');

const logger = createLogger();

const sns = new AWS.SNS({
  region: '..',
  accessKeyId: '..',
  secretAccessKey: '..'
});

logger.add(new WinstonSnsSumoLogic({
  level: 'error',
  sns,
  topicArn: '..'
}));

Options

  • level: Level of messages that should be logged. Defaults to info.
  • sns (required): The AWS.SNS instance to log to.
  • topicArn (required): The Amazon SNS topic ARN where the messages to be sent.
  • body: The base JSON message body. Should not contain timestamp, level, message, or meta. Forbidden fields will be overwritten.

Example

Let's say options.body was configured to be

{
  model: 'Falcon 9',
  flight: 20
}

When the the following message is logged

const landingDetails = {
  location: {
    latitude: 28.4859,
    longitude: -80.5444
  },
  fuel: 'nominal'
}
winston.info('successful landing', landingDetails);

Then the resulting Amazon SNS message body would be

{
  "model": "Falcon 9",
  "flight": 20,
  "timestamp": 1450748385666,
  "level": "info",
  "message": "successful landing",
  "meta": {
    "location": {
      "latitude": 28.4859,
      "longitude": -80.5444
    },
    "fuel": "nominal"
  }
}

Where timestamp is the Unix Epoch in milliseconds when the message was logged.

Justification

There is another winston-sns transport, but it does not work well with Sumo Logic. That transport is focused on sending text based messaged to Amazon SNS, where as this transport focuses on sending JSON based messages with Sumo Logic compatible timestamps.

Installation

$ npm install winston-sns-sumo-logic --save

Sumo Logic Setup

  1. Create a Sumo Logic HTTP Collector
  2. Create a Amazon SNS topic
  3. Add Sumo Logic HTTP Collector endpoint as an HTTPS subscriber to the new topic
  4. Subscribe to SNS Notifications
  5. Enable Raw Message Delivery
  6. Add winston-sns-sumo-logic as a new transport
  7. Configure with topic ARN
  8. Ensure AWS Access Key has permission to publish messages to Amazon SNS

Author: Ronald Chen

License: MIT

About

Winston Transport for Amazon SNS specialized for JSON logs in Sumo Logic

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published