Skip to content

fix(logger): remove subclassing and move unnecessary APIs #2334

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

Merged

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented May 26, 2023

Issue number: #2356

Summary

Long standing tech debt to remove logging.Logger sub-classing, and move backwards compatible private functions to compat.py to keep Logger public API cleaner.

Why?

If we were to add __getattr__, mypy would then fail to detect non-existent objects like logger.foo, because it can't infer from that.

Changes

Please provide a summary of what's being changed

  • Remove subclassing to prevent erroneous behaviour
  • Move backwards compatibility to compat.py.
    • Double check caller filename patch
  • Correct docstring for registered_handler and registered_formatter to say it picks up the original handler only for convenience.
    • This is due to niche customers wanting multiple handlers; it shall prevent confusion.
  • Proxy log_level to _logger.level to make it less error-prone

Historical events that made this possible now (older to recent)

User experience

Please share what the user experience looks like before and after this change

Escape hatching to standard python logging methods like addHandler, setLevel will work as expected and effect the underlying logger. However, mypy customers will receive a error at type checking - if necessary, we can port these into our Logger API on a per case basis.

image

Output

{
    "level": "DEBUG",
    "location": "<module>:7",
    "message": "hello from debug",
    "timestamp": "2023-05-26 16:50:51,239+0200",
    "service": "payment"
}

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

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

Acknowledgment

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

* develop:
  chore(deps-dev): bump aws-cdk from 2.80.0 to 2.81.0 (aws-powertools#2332)
  chore(deps-dev): bump coverage from 7.2.5 to 7.2.6 (aws-powertools#2326)
  chore(deps-dev): bump pytest-cov from 4.0.0 to 4.1.0 (aws-powertools#2327)
  chore(deps): bump actions/setup-python from 4.6.0 to 4.6.1 (aws-powertools#2325)
  fix(docs): use concrete secrets from settings (aws-powertools#2322)
  fix(logger): add setLevel function to set level programmatically (aws-powertools#2320)
  feat(parser): add support for parsing SQS events wrapped in Kinesis Firehose (aws-powertools#2294)
@heitorlessa heitorlessa requested a review from a team as a code owner May 26, 2023 10:23
@heitorlessa heitorlessa requested review from leandrodamascena and removed request for a team May 26, 2023 10:23
@boring-cyborg boring-cyborg bot added the logger label May 26, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 26, 2023
@heitorlessa heitorlessa added the tech-debt Technical Debt tasks label May 26, 2023
@codecov-commenter
Copy link

codecov-commenter commented May 26, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (719cdc0) 97.21% compared to head (70ba63e) 97.21%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2334   +/-   ##
========================================
  Coverage    97.21%   97.21%           
========================================
  Files          152      153    +1     
  Lines         6998     7006    +8     
  Branches       513      513           
========================================
+ Hits          6803     6811    +8     
  Misses         155      155           
  Partials        40       40           
Impacted Files Coverage Δ
aws_lambda_powertools/logging/compat.py 100.00% <100.00%> (ø)
aws_lambda_powertools/logging/logger.py 99.43% <100.00%> (+<0.01%) ⬆️
aws_lambda_powertools/logging/utils.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rubenfonseca rubenfonseca self-requested a review May 26, 2023 15:28
Copy link
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

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

Awesome!

@leandrodamascena leandrodamascena merged commit 0b4f866 into aws-powertools:develop Jun 1, 2023
@leandrodamascena leandrodamascena changed the title refactor(logger): remove subclassing and move unnecessary APIs fix(logger): remove subclassing and move unnecessary APIs Jun 2, 2023
@github-actions github-actions bot added the bug Something isn't working label Jun 2, 2023
roger-zhangg pushed a commit to roger-zhangg/aws-lambda-powertools-python that referenced this pull request Jun 5, 2023
sthulb pushed a commit that referenced this pull request Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement logger size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tech-debt Technical Debt tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Handler registered with addHandler not logging extra keys added by append_keys
4 participants