Skip to content

Commit

Permalink
fix(logger): ensure default keys are added when cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
heitorlessa committed Apr 1, 2022
1 parent 2b32ab2 commit 80cb6ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions aws_lambda_powertools/logging/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def remove_keys(self, keys: Iterable[str]):

def clear_state(self):
self.log_format = dict.fromkeys(self.log_record_order)
self.log_format.update(**self._build_default_keys())

@staticmethod
def _build_default_keys():
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,12 @@ def handler(event, context):

# THEN all standard keys should be available as usual
handler({}, lambda_context)
handler({}, lambda_context)

log = capture_logging_output(stdout)
first_log, second_log = capture_multiple_logging_statements_output(stdout)
for key in standard_keys:
assert key in log
assert key in first_log
assert key in second_log


def test_clear_state_keeps_exception_keys(lambda_context, stdout, service_name):
Expand Down

0 comments on commit 80cb6ec

Please sign in to comment.