Fix: StorageManager no longer interferes with root logger (#1405) #1419
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 fixes an issue where using StorageManager.get_local_copy() (or any ClearML utility that triggers logging initialization) would close user-defined logging handlers, such as [logging.FileHandler], if the user already configured logging. This caused log messages to stop appearing in user log files after the first ClearML call.
Details
Root cause:
ClearML’s logging initialization called [logging.config.dictConfig], which resets and closes all existing logging handlers, including those set up by the user.
Fix:
The patch adds a check in clearml/backend_config/log.py so that [dictConfig] is only called if the root logger has no handlers. This prevents ClearML from interfering with user logging setups.
I also added a fix that creates a shallow copy in clearml/debugging/log.py in the clear_logger_handlers() function. This function closes the handler before it is removed and modifies the loop to iterate over a shallow copy of the handlers list.
Test:
Added a test (test_storage_manager.py) to ensure that user-defined handlers remain open and receive log messages after calling StorageManager.get_local_copy().
Impact:
Backwards compatible:
If the user does not configure logging, ClearML will still set up logging as before.
Best practice:
This approach follows standard open-source library practices for interacting with Python’s logging system.
Closes: StorageManager affects root logger of logging #1405 (#1405)