Skip to content

fix(logger): child logger must respect log level #5950

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
merged 1 commit into from
Jan 29, 2025

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #5949

Summary

Changes

This PR addresses an issue where child loggers are unable to set different log levels from their parent loggers.

Currently, when creating a child logger using Powertools, the log level set for the child logger is not respected. This limits the ability to have different parts of an application log at different levels of verbosity.

Changes

  • Modified the Logger class initialization to check if it's a child logger
  • If it's a child logger, set the log level as specified in the constructor
  • Add tests

Example

from aws_lambda_powertools import Logger

parent_logger = Logger(service="payment", level="INFO")
child_logger = Logger(service="payment", child=True, level="DEBUG")

parent_logger.debug("This won't be logged")  # Won't be logged (INFO level)
child_logger.debug("This will be logged")    # Will be logged (DEBUG level)

Backwards Compatibility

This change is backwards compatible. Existing code using Powertools loggers will continue to work as before, with the added benefit of respecting log levels for child loggers when explicitly set.

User experience

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

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.

@leandrodamascena leandrodamascena requested a review from a team January 29, 2025 22:23
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 29, 2025
@leandrodamascena leandrodamascena linked an issue Jan 29, 2025 that may be closed by this pull request
@leandrodamascena leandrodamascena self-assigned this Jan 29, 2025
@github-actions github-actions bot added the bug Something isn't working label Jan 29, 2025
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.24%. Comparing base (7a45aa3) to head (c9a8465).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5950   +/-   ##
========================================
  Coverage    96.23%   96.24%           
========================================
  Files          234      234           
  Lines        11010    11013    +3     
  Branches       797      798    +1     
========================================
+ Hits         10596    10599    +3     
  Misses         327      327           
  Partials        87       87           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@anafalcao anafalcao left a comment

Choose a reason for hiding this comment

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

APPROVED 🚀

@leandrodamascena leandrodamascena merged commit 4adb504 into develop Jan 29, 2025
20 checks passed
@leandrodamascena leandrodamascena deleted the logger/child-log-level branch January 29, 2025 22:44
sinofseven pushed a commit to sinofseven/powertools-lambda-python-my-extend that referenced this pull request Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logger 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.

Bug: Child Logger doesn't respect loglevel
2 participants