Send logs to Amazon Cloudwatch using Winston.
$ npm install --save winston winston-cloudwatch
AWS configuration works using ~/.aws/credentials
as written in AWS JavaScript SDK guide.
As specified in the docs
The AWS SDK for Node.js doesn't select the region by default.
so you should take care of that. See the examples below.
If either the group or the stream do not exist they will be created for you.
Please refer to AWS CloudWatch Logs documentation for possible contraints that might affect you. Also have a look at AWS CloudWatch Logs limits.
var winston = require('winston'),
options = {
logGroupName: 'your-log-group',
logStreamName: 'your-log-stream'
};
winston.add(require('winston-cloudwatch'), options);
winston.error('log this', { and: 'this too' });
This is the list of options you could pass as argument to winston.add
:
- level - defaults to
info
- logGroupName
- logStreamName
- awsAccessKeyId
- awsSecretKey
- awsRegion
- jsonMessage -
boolean
, format the message as JSON
AWS keys are usually picked by aws-sdk so you don't have to specify them, I provided the option just in case. Remember that awsRegion
should still be set if you're using IAM roles.
Please refer to the provided example for more hints.