Description
Expected Behaviour
I would expected the output to be
AWS logger
NoneType: None
Current Behaviour
--- Logging error ---
Traceback (most recent call last):
File "/Users/kevin.flathers/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/logging/__init__.py", line 1160, in emit
msg = self.format(record)
^^^^^^^^^^^^^^^^^^^
File "/Users/kevin.flathers/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/logging/__init__.py", line 999, in format
return fmt.format(record)
^^^^^^^^^^^^^^^^^^
File "/Users/kevin.flathers/codebase/cz-common-python/.venv/lib/python3.12/site-packages/aws_lambda_powertools/logging/formatter.py", line 197, in format
extracted_exception, extracted_exception_name = self._extract_log_exception(log_record=record)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kevin.flathers/codebase/cz-common-python/.venv/lib/python3.12/site-packages/aws_lambda_powertools/logging/formatter.py", line 391, in _extract_log_exception
return self.formatException(log_record.exc_info), log_record.exc_info[0].__name__ # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?
Call stack:
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/kevin.flathers/codebase/cz-common-python/z.py", line 10, in <module>
aws_logger.warning('AWS logger', exc_info=True)
File "/Users/kevin.flathers/codebase/cz-common-python/.venv/lib/python3.12/site-packages/aws_lambda_powertools/logging/logger.py", line 544, in warning
return self._logger.warning(
Message: 'AWS logger'
Arguments: ()
Code snippet
import logging
from aws_lambda_powertools import Logger
python_logger = logging.getLogger(__name__)
aws_logger = Logger()
python_logger.warning('Python logger', exc_info=True)
print('\n\n')
aws_logger.warning('AWS logger', exc_info=True)
Possible Solution
It appears like AWS Power Tools Logger is throwing an error somewhere when exc_info
is set to True, but an exception was not raised. This is counter to how the Python logger works, where it just prints NoneType: None
Steps to Reproduce
Run the provided script
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi