简体   繁体   中英

AWS Lambda Function: new Logger() sometimes appends to previous log, instead of creating a new one

I'm working with AWS Lambda Functions (Python). In my function, I create a new Logger() object, which I use to log information throughout. It doesn't always create a new logging instance in CloudWatch. Sometimes it appends to a previous log. I don't understand the inconsistency.

I always do the logging the same way:

  • joblog = Logger(service="xxx", level="INFO")
  • joblog.info("xxx")

I'm executing the function via the "Test" tab, and also with scheduled events (from CloudWatch, with crontab entries).

Per @AnonCoward's link:

From How CloudWatch structures logs - AWS Lambda :

Each instance of a Lambda function has a dedicated log stream. If a function scales up, each concurrent instance has its own log stream . Each time an execution environment is reaped and a new environment is created in response to an invocation, this generates a new log stream . The naming convention for log streams is:

YYYY/MM/DD[Function version][Execution environment GUID]

A single execution environment writes to the same log stream during its lifetime . The log stream contains messages from that execution environment and also any output from your Lambda function's code. Every message is timestamped, including your custom logs, which means you do not need to output timestamps.

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