v2: Fix log level inheritance#24
Merged
Roasbeef merged 3 commits intobtcsuite:masterfrom Jul 28, 2025
Merged
Conversation
This was referenced Jul 23, 2025
This commit adds a unit test to assert the current, correct, behaviour of SubSystem in that it will create a new logger that does not inherit any log level changes from its parent after creation.
This commit adds a new `TestWithPrefixLevelInheritance` unit test which demonstrates that log level inheritance between parent loggers and child loggers created via "WithPrefix" does not work as expected.
In this commit, the bug demonstrated in the previous commit is fixed. Any child logger derived via WithPrefix will inherit a pointer to the same `level` variable of the parent meaning that any change inl log level will be reflected in the child logger.
8ba0244 to
f0b9cb6
Compare
Contributor
|
LGTM 🙏 |
Contributor
Author
|
cc @Roasbeef for merge |
Roasbeef
approved these changes
Jul 28, 2025
v2/handler_test.go
Outdated
| } | ||
|
|
||
| // Show that the buffer currently _does not_ contain the child log. | ||
| // NOTE: This is a bug and will be fixed in the next commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR, we fix log level inheritance of
WithPrefix.With this PR, we have the following behaviour:
WithPrefixis used to create a child logger, the log level is inherited from the parent - meaning that if the parent's level is changed after the child is created, the child's level will also be updated.SubSystemis used to create a child logger, the log level is independent from the parent after creation. Meaning that after creation, a change in log level of the parent/child will not be reflected in the other.