Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple Node.js module for logging on AWS CloudWatch using Winston
"use strict";
let winston = require("winston");
let cloudWatchTransport = require("winston-aws-cloudwatch");
const set = function (options) {
let logger = new winston.Logger({
transports: [
new winston.transports.Console({
timestamp: true,
colorize: true
})
]
});
const config = {
logGroupName: options.logGroupName,
logStreamName: options.logStreamName,
createLogGroup: false,
createLogStream: true,
awsConfig: {
accessKeyId: options.awsConfig.accessKeyId,
secretAccessKey: options.awsConfig.secretAccessKey,
region: options.awsConfig.region
},
formatLog: function (item) {
return item.level + ": " + item.message + " " + JSON.stringify(item.meta);
}
};
logger.add(cloudWatchTransport, config);
logger.level = "silly";
logger.stream = {
write: function (message, encoding) {
logger.info(message);
}
};
return logger;
};
module.exports = {
set: set
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.