Skip to content

ExecThread/winston-aws-cloudwatch

 
 

Repository files navigation

winston-aws-cloudwatch

npm Dependencies Build Status Coverage Status JavaScript Standard Style

A Winston transport for Amazon CloudWatch.

Usage

var CloudWatchTransport = require('winston-aws-cloudwatch')

winston.add(CloudWatchTransport, {
  logGroupName: '...', // REQUIRED
  logStreamName: '...', // REQUIRED
  createLogGroup: true,
  createLogStream: true,
  awsConfig: {
    accessKeyId: '...',
    secretAccessKey: '...',
    region: '...'
  },
  formatLogItem: function (item) {
    return item.level + ': ' + item.message + ' ' + JSON.stringify(item.meta)
  }
})

Error Handling

If, for any reason, logging to CloudWatch should fail, then the transport will emit an error event. It is recommended that you subscribe to this event to avoid crashes. Here's a basic example:

var config = { ... } // See above
var cwt = new CloudWatchTransport(config)

cwt.on('error', function (error) {
  console.error('Error logging to CloudWatch: ' + error.message)
})

winston.add(cwt)

But Why?

As you may have noticed, there is also winston-cloudwatch, which predates this module. After making some contributions to that one, I felt like writing my own version. Feel free to use whichever you like best.

Author

Tim De Pauw

License

MIT

About

A Winston transport for Amazon CloudWatch.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%