Repository navigation
Conversation
`setup_logger()` created and attached a new stderr `StreamHandler` on every call. The module already calls it once on import, so a user calling the public `setup_logger()` again, for example to change the log level, got a second handler and every message was printed twice. Create the stderr handler once at module level and attach that same handler in `setup_logger()`. `Logger.addHandler` skips a handler that is already attached, so repeated calls no longer add handlers, while the level passed in is still applied on every call. `propagate = False` is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
appium.common.logger.setup_logger()creates and attaches a new stderrStreamHandleron every call. The module already calls it once on import. So when a user calls the publicsetup_logger()again, for example to change the log level, every message is printed twice:Each further call adds one more copy.
Fix
setup_logger().Logger.addHandlerskips a handler that is already attached, so repeated calls don't add handlers. If the handler was removed, the next call attaches it again.levelpassed in is still applied on every call.propagate = Falseis unchanged.Tests
test/unit/common/logger_test.py:test_setup_logger_does_not_add_another_handler: callingsetup_logger()twice leaves the single stderr handler from import. Without the fix, there are two more handlers.test_setup_logger_updates_level: calling it again with a different level still changes the level, andpropagatestaysFalse.StreamHandlers, because pytest attaches its own capture handlers to non-propagating loggers while a test runs.ruff check,ruff format --check,mypy appiumand the full unit test suite pass.🤖 Generated with Claude Code