lazywithclass/winston-cloudwatch

Logs are not printing in the given log group name

Opened this issue · 2 comments

Hi ,

I am facing the issue logs are not printing in the given log group name. logs are printing in the lambda function name group.
please help me to resolve the issue.
any suggestions.

const winston = require('winston'),
WinstonCloudWatch = require('winston-cloudwatch');
const logger = new winston.createLogger({
format: winston.format.json(),
transports: [
new (winston.transports.Console)({
timestamp: true,
colorize: true,
})
]
});
if (process.env.NODE_ENV === 'production') {
const cloudwatchConfig = {
logGroupName: "test",
logStreamName: "test-dev",
awsAccessKeyId: "",
awsSecretKey: "
",,
awsRegion: "********",
messageFormatter: ({ level, message, additionalInfo }) => [${level}] : ${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}}
}
logger.add(new WinstonCloudWatch(cloudwatchConfig))
}

exports.handler = async (event) => {
// TODO implement
logger.info("index Lambda invoked");
logger.error('index Test log');
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda! index2'),
};
return response;
};

Thanks.

Have you tried running one of the examples? If so does that send logs to CloudWatch?
Could you please format the above code?

Hi @lazywithclass ,

Thanks for response.
Yes i tried ,logs are logging in lambda function group name instead of given group name.i gave correct format of the code, after submit of my code it was showing in different format.

const winston = require('winston'),
WinstonCloudWatch = require('winston-cloudwatch');
const logger = new winston.createLogger({
format: winston.format.json(),
transports: [
new (winston.transports.Console)({
timestamp: true,
colorize: true,
})
]
});

const cloudwatchConfig = {
logGroupName: "test",
logStreamName: "test-dev",
awsAccessKeyId: "",
awsSecretKey: "
**",
awsRegion: "us-east-1",
messageFormatter: ({ level, message, additionalInfo }) => [${level}] : ${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}}
}
logger.add(new WinstonCloudWatch(cloudwatchConfig))

exports.handler = async (event) => {
// TODO implement
logger.info("index Lambda invoked");
logger.error('index Test log');
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda! index'),
};
return response;
};

Thanks.