Skip to content

Commit bda7ca3

Browse files
committed
documentation
1 parent 45886a6 commit bda7ca3

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

docs/core/logging.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ Setting | Description | Environment variable | Attribute parameter
2929
**Service** | Sets **Service** key that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `Service`
3030
**Logging level** | Sets how verbose Logger should be (Information, by default) | `POWERTOOLS_LOG_LEVEL` | `LogLevel`
3131

32-
!!! warning "When using Lambda Log Format JSON"
33-
- And Powertools Logger output is set to `PascalCase` **`Level`** property name will be replaced by **`LogLevel`** as a property name.
34-
- The Lambda Application log level setting will control what is sent to CloudWatch. It takes precedence over **`POWERTOOLS_LOG_LEVEL`** and when setting it in code using **`[Logging(LogLevel = )]`**
35-
3632
### Example using AWS Serverless Application Model (AWS SAM)
3733

3834
You can override log level by setting **`POWERTOOLS_LOG_LEVEL`** environment variable in the AWS SAM template.
@@ -73,6 +69,51 @@ Here is an example using the AWS SAM [Globals section](https://docs.aws.amazon.c
7369
| **POWERTOOLS_LOGGER_LOG_EVENT** | Logs incoming event | `false` |
7470
| **POWERTOOLS_LOGGER_SAMPLE_RATE** | Debug log sampling | `0` |
7571

72+
73+
### Using AWS Lambda Advanced Logging Controls (ALC)
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.
76+
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+
79+
!!! warning "When using AWS Lambda Advanced Logging Controls (ALC)"
80+
- When Powertools Logger output is set to `PascalCase` **`Level`** property name will be replaced by **`LogLevel`** as a property name.
81+
- ALC takes precedence over **`POWERTOOLS_LOG_LEVEL`** and when setting it in code using **`[Logging(LogLevel = )]`**
82+
83+
```mermaid
84+
sequenceDiagram
85+
title Lambda ALC allows WARN logs only
86+
participant Lambda service
87+
participant Lambda function
88+
participant Application Logger
89+
90+
Note over Lambda service: AWS_LAMBDA_LOG_LEVEL="WARN"
91+
Lambda service->>Lambda function: Invoke (event)
92+
Lambda function->>Lambda function: Calls handler
93+
Lambda function->>Application Logger: Logger.Warning("Something happened")
94+
Lambda function-->>Application Logger: Logger.Debug("Something happened")
95+
Lambda function-->>Application Logger: Logger.Information("Something happened")
96+
97+
Lambda service->>Lambda service: DROP INFO and DEBUG logs
98+
99+
Lambda service->>CloudWatch Logs: Ingest error logs
100+
```
101+
102+
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+
**Priority of log level settings in Powertools for AWS Lambda**
105+
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+
We prioritise log level settings in this order:
109+
110+
1. AWS_LAMBDA_LOG_LEVEL environment variable
111+
2. Setting the log level in code using logger.setLevel()
112+
3. POWERTOOLS_LOG_LEVEL environment variable
113+
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.
115+
116+
76117
## Standard structured keys
77118

78119
Your logs will always include the following keys to your structured logging:

0 commit comments

Comments
 (0)