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
+11-7Lines changed: 11 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -72,14 +72,19 @@ Here is an example using the AWS SAM [Globals section](https://docs.aws.amazon.c
72
72
73
73
### Using AWS Lambda Advanced Logging Controls (ALC)
74
74
75
-
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. Regardless of the output format setting in Lambda, Powertools for AWS Lambda will always output JSON formatted logging messages.
75
+
!!! question "When is it useful?"
76
+
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.
76
77
77
-
When you have this feature enabled, log messages that don’t meet the configured log level are discarded by Lambda. 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.
78
+
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.
79
+
80
+
When enabled, you should keep `Logger` and ALC log level in sync to avoid data loss.
78
81
79
82
!!! warning "When using AWS Lambda Advanced Logging Controls (ALC)"
80
83
- When Powertools Logger output is set to `PascalCase`**`Level`** property name will be replaced by **`LogLevel`** as a property name.
81
84
- ALC takes precedence over **`POWERTOOLS_LOG_LEVEL`** and when setting it in code using **`[Logging(LogLevel = )]`**
82
85
86
+
Here's a sequence diagram to demonstrate how ALC will drop both `Information` and `Debug` logs emitted from `Logger`, when ALC log level is stricter than `Logger`.
87
+
83
88
```mermaid
84
89
sequenceDiagram
85
90
title Lambda ALC allows WARN logs only
@@ -88,6 +93,7 @@ sequenceDiagram
88
93
participant Application Logger
89
94
90
95
Note over Lambda service: AWS_LAMBDA_LOG_LEVEL="WARN"
96
+
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.
103
-
104
108
**Priority of log level settings in Powertools for AWS Lambda**
105
109
106
-
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.
107
-
108
110
We prioritise log level settings in this order:
109
111
110
112
1. AWS_LAMBDA_LOG_LEVEL environment variable
111
113
2. Setting the log level in code using `[Logging(LogLevel = )]`
112
114
3. POWERTOOLS_LOG_LEVEL environment variable
113
115
114
-
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.
116
+
If you set `Logger`level lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda.
115
117
118
+
> **NOTE**
119
+
> 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