generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 455
Closed
Labels
Description
Expected Behaviour
The following test should pass
def test_logger_with_caplog_with_appended_keys(caplog):
caplog.set_level("INFO")
logger = Logger(service="abcd")
logger.info("testing, testing...")
logger.append_keys(
context={
"testing": "true",
},
)
logger.info("testing, testing, now with context...")
assert len(caplog.records) == 2
assert caplog.records[0].message == "testing, testing..."
assert caplog.records[1].message == "testing, testing, now with context..."
assert caplog.records[1].context == {"testing": "true"}
Current Behaviour
The above test fails with error AttributeError: 'LogRecord' object has no attribute 'context'
.
But, the test below passes:
def test_logger_with_caplog_with_extra(caplog, service_name):
caplog.set_level("INFO")
logger = Logger(service=service_name)
logger.info("testing, testing...")
logger.thread_safe_append_keys(
context={
"testing": "true",
},
)
logger.info(
"testing, testing, now with extra...",
extra={
"context": {"testing": "true"},
},
)
assert len(caplog.records) == 2
assert caplog.records[0].message == "testing, testing..."
assert caplog.records[1].message == "testing, testing, now with extra..."
assert caplog.records[1].context == {"testing": "true"}
Code snippet
Provided above ^
Possible Solution
No response
Steps to Reproduce
- Add tests above to
tests/functional/logger/required_dependencies/test_logger.py
- Run
make test
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Coming soon