Write buynan logs to Amazon Web Services CloudWatch.
npm install bunyan-aws --save
var bunyan = require('bunyan');
var os = require('os');
var CloudWatchStream = require('bunyan-aws');
var myStream = new CloudWatchStream({
logGroupName: 'MyApplicationLogs',
logStreamName: 'MyStream-' + os.hostname(),
cloudWatchOptions: {
region: 'eu-central-1',
sslEnabled: true
}
});
var log = bunyan.createLogger({
name: 'logger',
streams: [{
stream: myStream,
type: 'raw',
level: 'info',
}]
};
myStream.on('error', function (err) {
console.error('Error in Cloud Watch stream', err);
});
This package uses the AWS SDK to write the logs to CloudWatch. You must set the AWS Credentials via one of the first three methods described here.
The log group must exist in CloudWatch.
- Sign into the AWS console
- Click on CloudWatch found under Services > Management
- Click on Logs
- Select Actions > Create log group
You may use an existing log stream. However if the stream is not found, it will be created for you. The package assumes it is the only source writing to the stream. Errors will occur if other sources write to the same stream.
These options are passed directly to the AWS SDK
This project was created by Aaron Schinkowitch (@schinkowitch), and is based on the work of Mirko Kiefer's bunyan-cloudwatch and Maurice Butler's bunyan-loggly. Hao Nguyen has made several fixes and improvements.