Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logger): clear_state should keep custom key formats #1095

Merged
merged 3 commits into from
Apr 8, 2022
Merged

fix(logger): clear_state should keep custom key formats #1095

merged 3 commits into from
Apr 8, 2022

Conversation

eliasbrange
Copy link
Contributor

@eliasbrange eliasbrange commented Apr 6, 2022

Issue #, if available: #1084

Description of changes:

When using clear_state=True, overriden formats for standard logging keys like location and timestamp was being overriden with the default formats. Overriding the formats are explained in the docs like this:

from aws_lambda_powertools import Logger

date_format = "%m/%d/%Y %I:%M:%S %p"
location_format = "[%(funcName)s] %(module)s"

# override location and timestamp format
logger = Logger(service="payment", location=location_format, datefmt=date_format)

Issue was that when clear_state=True was used, the default keys were reset to their defaults (by the fix implemented in #1088). This fix saves the formatting keys on instantiation and uses those instead when clear_state is called.

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 6, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 6, 2022

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.

@github-actions github-actions bot added the bug Something isn't working label Apr 6, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 6, 2022

Codecov Report

Merging #1095 (4318dcc) into develop (f24332d) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop    #1095   +/-   ##
========================================
  Coverage    99.96%   99.96%           
========================================
  Files          119      119           
  Lines         5377     5377           
  Branches       613      613           
========================================
  Hits          5375     5375           
  Partials         2        2           
Impacted Files Coverage Δ
aws_lambda_powertools/logging/formatter.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f24332d...4318dcc. Read the comment docs.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one suggestion on tests so we reduce the use of regex to improve test perf and ease future maintenance for the untrained eye.

tests/functional/test_logger.py Outdated Show resolved Hide resolved
@heitorlessa heitorlessa changed the title fix(logger): clear_state should now keep custom key formats fix(logger): clear_state should keep custom key formats Apr 8, 2022
@heitorlessa heitorlessa merged commit 86288b6 into aws-powertools:develop Apr 8, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 8, 2022

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@eliasbrange eliasbrange deleted the fix/logger-clear-state-respect-custom-format-strings branch April 8, 2022 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants