Skip to content

Commit fc86d17

Browse files
committed
fix: str formatting for reserved keys only #38
1 parent 392d547 commit fc86d17

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

aws_lambda_powertools/logging/logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(self, **kwargs):
6262
datefmt = kwargs.pop("datefmt", None)
6363

6464
super(JsonFormatter, self).__init__(datefmt=datefmt)
65+
self.reserved_keys = ["timestamp", "level", "location"]
6566
self.format_dict = {
6667
"timestamp": "%(asctime)s",
6768
"level": "%(levelname)s",
@@ -76,10 +77,12 @@ def format(self, record): # noqa: A003
7677

7778
log_dict = {}
7879
for key, value in self.format_dict.items():
79-
if value:
80+
if value and key in self.reserved_keys:
8081
# converts default logging expr to its record value
8182
# e.g. '%(asctime)s' to '2020-04-24 09:35:40,698'
8283
log_dict[key] = value % record_dict
84+
else:
85+
log_dict[key] = value
8386

8487
if isinstance(record_dict["msg"], dict):
8588
log_dict["message"] = record_dict["msg"]

0 commit comments

Comments
 (0)