I am working on a python lambda code, see sample below. when I use logger utility vs simply using print statement in python, where does it logs the information?
import logging
logger = logging.getLogger("module1")
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
try:
#do something
except Exception as error:
loggger.exception(error)
They are written to a CloudWatch log group. Go to the Monitoring tab in your function and there should be a link to see the logs in Cloudwatch.
Read more here:
Goto Resource Groups > CloudWatch > Logs > Log groups.
Even better way of search a particular log is as below:
CloudWatch > Logs > insights.
Sample Query below
fields @timestamp, @message, @logStream
| filter @message like /Error/
| sort @timestamp desc
| limit 20
In the result @logStream column will give you a direct link to that log stream containing the searched message.
Note: If you have selected multiple log groups in the dropdown, you would see the log stream name but the anchor link to it will not be enabled - it only works with the single log group/lambda search selection. You can also apply Regex between the two forwarded slash.
filter @message like /your regex goes here/
When you click on the log stream link and go to the log stream page. There also you can deep search to get the log stream link for your search.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.