Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs are not printing in the given log group name #171

Open
mallikarjuna11421 opened this issue Dec 8, 2021 · 2 comments
Open

Logs are not printing in the given log group name #171

mallikarjuna11421 opened this issue Dec 8, 2021 · 2 comments

Comments

@mallikarjuna11421
Copy link

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 mallikarjuna11421 changed the title Logs are not printing in tge given log group name Logs are not printing in the given log group name Dec 8, 2021
@lazywithclass
Copy link
Owner

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

@mallikarjuna11421
Copy link
Author

mallikarjuna11421 commented Dec 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants