You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/logging.md
+20-14
Original file line number
Diff line number
Diff line change
@@ -596,12 +596,18 @@ via `samplingRate` attribute on annotation.
596
596
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.5
597
597
```
598
598
599
-
## AWS Lambda Advanced Logging Controls
600
-
With AWS [Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced), you can control the output format of your logs as either `TEXT` or `JSON` and specify the minimum accepted log level for your application.
601
-
Regardless of the output format setting in Lambda, Powertools for AWS Lambda will always output JSON formatted logging messages.
599
+
## AWS Lambda Advanced Logging Controls (ALC)
602
600
603
-
When you have this feature enabled, log messages that don’t meet the configured log level are discarded by Lambda.
604
-
For example, if you set the minimum log level to `WARN`, you will only receive `WARN` and `ERROR` messages in your AWS CloudWatch Logs, all other log levels will be discarded by Lambda.
601
+
!!!question "When is it useful?"
602
+
When you want to set a logging policy to drop informational or verbose logs for one or all AWS Lambda functions, regardless of runtime and logger used.
603
+
604
+
<!-- markdownlint-disable MD013 -->
605
+
With [AWS Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced){target="_blank"}, you can enforce a minimum log level that Lambda will accept from your application code.
606
+
607
+
When enabled, you should keep `Logger` and ALC log level in sync to avoid data loss.
608
+
609
+
Here's a sequence diagram to demonstrate how ALC will drop both `INFO` and `DEBUG` logs emitted from `Logger`, when ALC log level is stricter than `Logger`.
610
+
<!-- markdownlint-enable MD013 -->
605
611
606
612
```mermaid
607
613
sequenceDiagram
@@ -610,29 +616,29 @@ sequenceDiagram
610
616
participant Application Logger
611
617
612
618
Note over Lambda service: AWS_LAMBDA_LOG_LEVEL="WARN"
619
+
Note over Application Logger: POWERTOOLS_LOG_LEVEL="DEBUG"
Logger will automatically listen for the `AWS_LAMBDA_LOG_FORMAT` and `AWS_LAMBDA_LOG_LEVEL` environment variables, and change behaviour if they’re found to ensure as much compatibility as possible.
625
-
626
630
### Priority of log level settings in Powertools for AWS Lambda
627
631
628
-
When the Advanced Logging Controls feature is enabled, we are unable to increase the minimum log level below the `AWS_LAMBDA_LOG_LEVEL` environment variable value, see [AWS Lambda service documentation](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-log-level) for more details.
629
-
630
632
We prioritise log level settings in this order:
631
633
632
634
1.`AWS_LAMBDA_LOG_LEVEL` environment variable
633
635
2.`POWERTOOLS_LOG_LEVEL` environment variable
634
636
635
-
In the event you have set `POWERTOOLS_LOG_LEVEL` to a level lower than the ACL setting, Powertools for AWS Lambda will output a warning log message informing you that your messages will be discarded by Lambda.
637
+
If you set `Logger` level lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda.
638
+
639
+
> **NOTE**
640
+
>
641
+
> With ALC enabled, we are unable to increase the minimum log level below the `AWS_LAMBDA_LOG_LEVEL` environment variable value, see [AWS Lambda service documentation](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-log-level){target="_blank"} for more details.
0 commit comments