winston-cloudwatch icon indicating copy to clipboard operation
winston-cloudwatch copied to clipboard

Logs are not printing in the given log group name

Open mallikarjuna11421 opened this issue 3 years ago • 2 comments
trafficstars

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.

mallikarjuna11421 avatar Dec 08 '21 05:12 mallikarjuna11421

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

lazywithclass avatar Dec 08 '21 21:12 lazywithclass

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.

mallikarjuna11421 avatar Dec 09 '21 06:12 mallikarjuna11421