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): fix a bug when child logger didn't get all the parent's attributes #1267

Conversation

shdq
Copy link
Contributor

@shdq shdq commented Feb 2, 2023

When createChild create a child logger without options, it didn't inherit the parents' attributes.

Attributes affected:

  • logLevel
  • customConfigService
  • logFormatter

Example:

// With this logger, all the INFO logs will be printed
const logger = new Logger({
    logLevel: 'INFO'
});

// With this logger, we expect INFO logs too
const childLogger = parentLogger.createChild();

But it will be DEBUG since it is the default value:

-   "logLevel": "INFO",
+   "logLevel": "DEBUG",

Description of your changes

Missing parent's attributes are added to options before merging with child options that suppose to overwrite them.

It was missed because existing tests compare attributes against default values. I added a test with all possible parent's options with non-default values and found all the affected attributes.

How to verify this change

Related issues, RFCs

Issue number: #1264

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published
  • The PR title follows the conventional commit semantics

Breaking change checklist

  • I have documented the migration process
  • I have added, implemented necessary 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/L PRs between 100-499 LOC label Feb 2, 2023
@github-actions github-actions bot added the bug Something isn't working label Feb 3, 2023
@saragerion
Copy link
Contributor

Thanks for opening this PR. We have a number of other items high on priority before we can look into this issue and verify this PR, but we'll get back to you.

@shdq
Copy link
Contributor Author

shdq commented Feb 3, 2023

Hi @saragerion, thank you for the reply!

That is great that test failed in CI because I ran it locally several times, and it was passed. I revisited the code, and since logsSampled value depends on the random function (see setLogsSampled() method in Loggerclass) test finishes with different results. I adjusted the test and made a minor change to the implementation.

@dreamorosi dreamorosi self-requested a review February 8, 2023 14:20
@dreamorosi dreamorosi linked an issue Feb 8, 2023 that may be closed by this pull request
2 tasks
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

Thank you @shdq for the bias for action on this PR.

I've run the integration tests on this branch and they are passing.

Let's go!

@dreamorosi dreamorosi merged commit 84ab4b9 into aws-powertools:main Feb 9, 2023
@danrivett
Copy link

I just ran into this issue with child loggers not inheriting the parent's logLevel, so thanks for fixing this, it's much appreciated.

If I'm correct, it looks like it should be released as part of an upcoming 1.6.0 version, so looking forward to migrating to that once published.

@danrivett
Copy link

danrivett commented Mar 2, 2023

I can confirm that we upgraded to 1.6.0 today and it fixed our child logLevel issue perfectly 🎉 Thank you!

@dreamorosi
Copy link
Contributor

dreamorosi commented Mar 2, 2023

Indeed, we have just released the new version and the issue should be fixed.

Happy to hear, thank you for following up!

@shdq
Copy link
Contributor Author

shdq commented Mar 2, 2023

I'm glad to hear that. Thank you for the feedback!

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/L PRs between 100-499 LOC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: LogFormatter not forwarded to child loggers
4 participants