Expected Behaviour
POWERTOOLS_LOG_LEVEL (and POWERTOOLS_LOGGER_SAMPLE_RATE`) should decide what log lines Powertools emits.
Lambda’s applicationLogLevelV2 should only act as a platform filter (drop logs below that threshold before forwarding to CloudWatch).
Examples:
- If
POWERTOOLS_LOG_LEVEL=INFO and applicationLogLevelV2=DEBUG, then only INFO+ should be emitted, and those should appear in CloudWatch.
- If
POWERTOOLS_LOG_LEVEL=DEBUG and applicationLogLevelV2=INFO, then DEBUG logs should be emitted by Powertools but dropped by the platform, so only INFO+ appear in CloudWatch.
Current Behaviour
applicationLogLevelV2=DEBUG causes all logs, including DEBUG, to appear in CloudWatch, even if POWERTOOLS_LOG_LEVEL=INFO.
In effect, the Lambda application log level is overriding Powertools’ log level instead of filtering logs after emission.
POWERTOOLS_LOGGER_SAMPLE_RATE becomes ineffective when combined with applicationLogLevelV2=DEBUG, because all requests in a container emit DEBUG regardless of Powertools’ base level.
Code snippet
from aws_lambda_powertools import Logger
logger = Logger()
@logger.inject_lambda_context
def handler(event, context):
logger.debug("Debug log line")
logger.info("Info log line")
return {"status": "ok"}
Possible Solution
Ensure Powertools filtering (POWERTOOLS_LOG_LEVEL, POWERTOOLS_LOGGER_SAMPLE_RATE) applies before logs are emitted.
The Lambda runtime should then filter logs again according to applicationLogLevelV2.
If this behavior is by design, document clearly that:
- applicationLogLevelV2=DEBUG will force
DEBUG logs through, regardless of Powertools config.
- Sampling (
POWERTOOLS_LOGGER_SAMPLE_RATE) works per-container and will appear overridden if applicationLogLevelV2=DEBUG is set.
Steps to Reproduce
Case 1
- applicationLogLevelV2 = INFO
POWERTOOLS_LOG_LEVEL = DEBUG
- Behaviour: Only INFO+ appear.
- ✅ Expected: Only INFO+ appear. (works correctly)
Case 2
- applicationLogLevelV2 = DEBUG
POWERTOOLS_LOG_LEVEL = INFO
- Behaviour:
DEBUG logs also appear.
- ❌ Expected: Only INFO+ logs, since Powertools should suppress DEBUG.
Case 3
- applicationLogLevelV2 = DEBUG
POWERTOOLS_LOG_LEVEL = INFO
POWERTOOLS_LOGGER_SAMPLE_RATE = 0.5
- Behaviour: All requests show DEBUG logs.
- ❌ Expected: Only ~50% of requests should show DEBUG logs.
Case 4
- applicationLogLevelV2 = INFO
POWERTOOLS_LOG_LEVEL = INFO
POWERTOOLS_LOGGER_SAMPLE_RATE = 0.5
- Behaviour: Only INFO+ appear.
- ❌ Expected: Some requests/containers show DEBUG logs due to sampling.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
Expected Behaviour
POWERTOOLS_LOG_LEVEL (andPOWERTOOLS_LOGGER_SAMPLE_RATE`) should decide what log lines Powertools emits.Lambda’s applicationLogLevelV2 should only act as a platform filter (drop logs below that threshold before forwarding to CloudWatch).
Examples:
POWERTOOLS_LOG_LEVEL=INFOand applicationLogLevelV2=DEBUG, then onlyINFO+should be emitted, and those should appear in CloudWatch.POWERTOOLS_LOG_LEVEL=DEBUGand applicationLogLevelV2=INFO, thenDEBUGlogs should be emitted by Powertools but dropped by the platform, so onlyINFO+appear in CloudWatch.Current Behaviour
applicationLogLevelV2=DEBUG causes all logs, including
DEBUG, to appear in CloudWatch, even ifPOWERTOOLS_LOG_LEVEL=INFO.In effect, the Lambda application log level is overriding Powertools’ log level instead of filtering logs after emission.
POWERTOOLS_LOGGER_SAMPLE_RATEbecomes ineffective when combined withapplicationLogLevelV2=DEBUG, because all requests in a container emitDEBUGregardless of Powertools’ base level.Code snippet
Possible Solution
Ensure Powertools filtering (
POWERTOOLS_LOG_LEVEL,POWERTOOLS_LOGGER_SAMPLE_RATE) applies before logs are emitted.The Lambda runtime should then filter logs again according to applicationLogLevelV2.
If this behavior is by design, document clearly that:
DEBUGlogs through, regardless of Powertools config.POWERTOOLS_LOGGER_SAMPLE_RATE) works per-container and will appear overridden if applicationLogLevelV2=DEBUG is set.Steps to Reproduce
Case 1
POWERTOOLS_LOG_LEVEL = DEBUGCase 2
POWERTOOLS_LOG_LEVEL = INFODEBUGlogs also appear.Case 3
POWERTOOLS_LOG_LEVEL = INFOPOWERTOOLS_LOGGER_SAMPLE_RATE = 0.5Case 4
POWERTOOLS_LOG_LEVEL = INFOPOWERTOOLS_LOGGER_SAMPLE_RATE = 0.5Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs