Skip to content

Commit 133f260

Browse files
author
Michael Brewer
committed
feat(logger): readable log_dict seq
Ensure that the initial key seq is: timestamp,level,location,message Closes #138
1 parent 8da0cce commit 133f260

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

aws_lambda_powertools/logging/formatter.py

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self, **kwargs):
5353
"timestamp": "%(asctime)s",
5454
"level": "%(levelname)s",
5555
"location": "%(funcName)s:%(lineno)d",
56+
"message": "",
5657
}
5758
self.format_dict.update(kwargs)
5859

tests/functional/test_aws_lambda_logging.py

+13
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,16 @@ class Unserializable:
116116
# THEN json_default should not be in the log message and the custom unserializable handler should be used
117117
assert log_dict["message"]["x"] == "<non-serializable: Unserializable>"
118118
assert "json_default" not in log_dict
119+
120+
121+
def test_log_dict_key_seq(stdout):
122+
# GIVEN any logger configuration
123+
logger = Logger(level="INFO", stream=stdout, another="xxx")
124+
125+
# WHEN logging a message
126+
logger.info("Message")
127+
128+
log_dict: dict = json.loads(stdout.getvalue())
129+
130+
# THEN the key sequence should be `timestamp,level,location,message`
131+
assert ",".join(list(log_dict.keys())[:4]) == "timestamp,level,location,message"

0 commit comments

Comments
 (0)