Repository navigation
Bugfixes and enhancements to logging module - #1179
Open
jamesquilty wants to merge 6 commits into
Open
jamesquilty wants to merge 6 commits into
jamesquilty wants to merge 6 commits into
Conversation
added 6 commits
November 22, 2026 11:07
Fixes issue micropython#928. Signed-off-by: James Quilty <James.Quilty@vuw.ac.nz>
The root logger's handler level should be NOTSET (the default) because named loggers which don't have handlers fall-back to using the root handler. If the named logger's level is set lower than the root handler's level then messages which would be expected to be logged by the named logger are unexpectedly dropped by the root handler. Signed-off-by: James Quilty <James.Quilty@vuw.ac.nz>
Signed-off-by: James Quilty <James.Quilty@vuw.ac.nz>
Fixes micropython#979. Signed-off-by: James Quilty <James.Quilty@vuw.ac.nz>
The "disabled" attribute defaults to False: loggers emit messages normally. When set with 'logger.disabled = True', this attribute disables logger output by making the isEnabled() method return False, silently bypassing the logger's handlers. Disabling logger output has a number of use cases, it is particularly useful when running unit tests where the log output can become more of a hindrance than a help. This commit provides feature parity with the CPython standard library, which implements logger disabling in the same manner. Signed-off-by: James Quilty <James.Quilty@vuw.ac.nz>
The changes introduce backward-compatible bug fixes and functionality, therefore the minor version number should be increased under semantic versioning rules. Signed-off-by: James Quilty <James.Quilty@vuw.ac.nz>
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.
Summary
This PR introduces the following changes:
shutdown()preventing removal of loggersshutdown function of logging module does not empty _loggers #928.
basicConfig()to clarify it configures the root loggerlogging.basicConfig(force=False) on empty handler list never initializes Formatter and Handler #979.
basicConfig()where the root handler level is set.Formatter.format()to userecord.__dict__.Each change is made via one commit and details may be found in commit message bodies. Complex changes not described in a prior issue follow.
3. Fix for
basicConfig()setting the root handler levelNamed loggers without handlers fall-back to using the root handler which should be
NOTSETby default. The logging module 0.6.2 sets the root logger's level, with the consequence that if the named logger's level is set lower than the root handler's level then messages which would be expected to be logged by the named logger are unexpectedly dropped by the root handler. The fix is to set the root logger level toNOTSETby default [this is also the CPython default].5. Allow logger output to be disabled by setting an attribute
This commit provides feature parity with the CPython standard library, which implements logger disabling via an attribute
logger.disabled.This feature does not change the existing behaviour: loggers emit messages normally by default. Loggers can be disabled dynamically by the statement
logger.disabled = Truewhich disables logger output by making theisEnabled()method returnFalse, silently bypassing the logger's handlers. Output is restored by the statementlogger.disabled = FalseDisabling logger output has a number of use cases, it is particularly useful for temporarily disabling logger output in unit tests where the log messages can become more of a hindrance than a help.
Testing
Manual unit testing on the REPL and casual integration testing in an existing code has been performed on the ESP32 port.
Generative AI
I did not use generative AI tools when creating this PR.