Description
Expected Behaviour
I often use a logging config for fine grained control over the logging level of third party dependencies in a lambda application. I often need to set the overall level of an application to DEBUG or INFO but there are some very chatty libraries that obscure useful information so I set them to WARNING or ERROR. I would expect these levels to be preserved when copying them over to the powertools logger.
Current Behaviour
Current behavior is to set all existing loggers to the level of the powertools logger. It's unclear why this is necessary, as levels below the powertools logger won't get displayed anyway (e.g. DEBUG on a library when the powertools logger is INFO) and overriding higher levels to lower levels causes undesired messages to be displayed (e.g. overriding WARNING and setting it to INFO). At the very least this should be configurable. It also has odd behavior because if the logging configuration has a level set one level down, e.g. chatty_library.submodule
that does not get overridden, so if it's higher than chatty_library
it will get blocked.
Code snippet
from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging import utils as logging_utils
logging_config = {'version': 1, 'disable_existing_loggers': False, 'root': {'level': 'DEBUG', 'propogate': True}, 'loggers': {
'botocore': {'level': 'INFO'}, 'chatty_library': {'level': 'ERROR'}, 'chatty_library_2.submodule': {'level': 'ERROR'}}}
logger = Logger(level='DEBUG')
logging.config.dictConfig(logging_config)
logging_utils.copy_config_to_registered_loggers(source_logger=logger)
logging.getLogger('chatty_library').info('foo') # Shows up in logs
logging.getLogger('chatty_library_2.submodule').info('foo') # Missing from logs, as expected
Possible Solution
Don't override log level in existing loggers, or make it configurable as an option to pass to copy_config_to_registered_loggers
.
It does seem that setting the logging config AFTER copying the loggers may set the values to the desired state but not sure if there are any side effects from doing it in this order.
Steps to Reproduce
See code sample.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.11
Packaging format used
PyPi
Debugging logs
No response
Metadata
Metadata
Assignees
Type
Projects
Status