简体   繁体   中英

where are the logs written to in aws lambda with python logger utility?

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.

  1. Select lambda in which you want to search the log in log groups dropdown above query window.
  2. Select the time range through which you want to search the log.

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.

  1. Select on Gear icon 在此处输入图像描述 at the top right corner.
  2. Checkmark "log stream name" .
  3. Then you can search in "Filter events" search box and goto the particular log location.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM