From 3823ef749ef005fc9fb2db6cbd2dc99097d5930f Mon Sep 17 00:00:00 2001 From: Katsuyuki Takahashi Date: Fri, 26 Sep 2025 19:50:29 +0900 Subject: [PATCH 1/2] docs(logger): clarify Advanced Logging Controls interaction with sampling --- docs/core/logger.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/core/logger.md b/docs/core/logger.md index 41c52b69db4..b6c15a9fb66 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -409,6 +409,11 @@ We prioritise log level settings in this order: 2. Explicit log level in `Logger` constructor, or by calling the `logger.setLevel()` method 3. `POWERTOOLS_LOG_LEVEL` environment variable +!!! info "AWS CDK and Advanced Logging Controls" + When using AWS CDK's `applicationLogLevelV2` parameter or setting log levels through the Lambda console, AWS Lambda automatically sets the `AWS_LAMBDA_LOG_LEVEL` environment variable. This means Lambda's log level takes precedence over Powertools for AWS configuration, potentially overriding both `POWERTOOLS_LOG_LEVEL` and sampling settings. + + **Example**: If you set `applicationLogLevelV2=DEBUG` in CDK while having `POWERTOOLS_LOG_LEVEL=INFO`, the DEBUG level will be used because Lambda automatically sets the environment variable `AWS_LAMBDA_LOG_LEVEL` to the debug level. + If you set `Logger` level lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda. > **NOTE** @@ -825,6 +830,8 @@ Use sampling when you want to dynamically change your log level to **DEBUG** bas You can use values ranging from `0.0` to `1` (100%) when setting `POWERTOOLS_LOGGER_SAMPLE_RATE` env var, or `sampling_rate` parameter in Logger. +**AWS Lambda Advanced Logging Controls (ALC)** settings can affect Sampling behavior. See [how it works](#aws-lambda-advanced-logging-controls-alc). + ???+ tip "Tip: When is this useful?" Log sampling allows you to capture debug information for a fraction of your requests, helping you diagnose rare or intermittent issues without increasing the overall verbosity of your logs. From 80247995ede7a876bd52c6236b1ec60b9900b2b7 Mon Sep 17 00:00:00 2001 From: Katsuyuki Takahashi Date: Sat, 27 Sep 2025 01:14:52 +0900 Subject: [PATCH 2/2] docs(logger): fix broken AWS Lambda ALC documentation link --- docs/core/logger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index b6c15a9fb66..abc44c11ada 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -375,7 +375,7 @@ If you want to access the numeric value of the current log level, you can use th 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. -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. +With [AWS Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-log-level.html#monitoring-cloudwatchlogs-log-level-setting){target="_blank"}, you can enforce a minimum log level that Lambda will accept from your application code. When enabled, you should keep `Logger` and ALC log level in sync to avoid data loss.