Reputation: 55
I am using Lambda function for populating Dynamo DB. I need to log the event details in cloudwatch to know the exception if some occurs. I am able to configure cloudwatch logs for the lambda function but it is showing other debug statements that is leading to unwanted logging. Is there any way to configure that.Any help will be appreciated.
Upvotes: 3
Views: 3609
Reputation: 3287
OK, I think I misunderstood your question. Apparently (from your comment) you're using log4j. The way to set log4j logging level is:
logger = Logger.getRootLogger(); // or Logger.getLogger("com.foo");
logger.setLevel(Level.ERROR);
This is standard log4j use, regardless of Lambda. A more Lambda-specific question might be how to control logging without changing your source code. Currently the best answer to that is using Lambda aliases, which would be clumsy, but soon Lambda will support environment variables as part of the function configuration and you could use that.
Upvotes: 1
Reputation: 66
You have to use the exception handling mechanism in your code. if any of error occur in your code then catch block should run and there you can use stacktrace methods for tracing the error. The stack trace method can be different in different languages. For Cloudwatch log you can use simple console output methods according to languages.
Upvotes: 0
Reputation: 3287
Each invocation will get three log lines from Lambda: START, END, and REPORT. All other log lines are from customer code (or modules used by customer code), or else a stack trace from an unhandled exception in user code, so it's up to you to control that.
Upvotes: 1