mirror of
https://github.com/clearml/clearml
synced 2025-06-26 18:16:07 +00:00
Fix: prevent StorageManager from interfering with root logger (#1405)
This commit is contained in:
parent
5a5ff31a5b
commit
449ae18f00
@ -41,5 +41,9 @@ def initialize(
|
||||
Logger.manager.loggerClass = _Logger
|
||||
|
||||
if logging_config is not None:
|
||||
# Use deepcopy since Python's logging infrastructure might modify the dict
|
||||
logging.config.dictConfig(deepcopy(dict(logging_config)))
|
||||
root_logger = logging.getLogger()
|
||||
#added a check to avoid calling dictConfig
|
||||
#if the root user has already set up their own logging.
|
||||
#prevents ClearML from closing their handlers.
|
||||
if not root_logger.handlers:
|
||||
logging.config.dictConfig(deepcopy(dict(logging_config)))
|
||||
|
@ -164,8 +164,10 @@ class LoggerRoot(object):
|
||||
loggers = [logging.getLogger()] + list(logging.Logger.manager.loggerDict.values())
|
||||
for logger in loggers:
|
||||
handlers = getattr(logger, "handlers", [])
|
||||
for handler in handlers:
|
||||
# Iterate over a copy to avoid modifying the list while removing handlers
|
||||
for handler in handlers[:]:
|
||||
if isinstance(handler, ClearmlLoggerHandler):
|
||||
handler.close()
|
||||
logger.removeHandler(handler)
|
||||
|
||||
|
||||
|
23
test_storage_manager.py
Normal file
23
test_storage_manager.py
Normal file
@ -0,0 +1,23 @@
|
||||
import logging
|
||||
from rich.logging import RichHandler
|
||||
from clearml.storage.manager import StorageManager
|
||||
|
||||
def test_storage_manager_does_not_break_root_logger(tmp_path):
|
||||
log_file = tmp_path / "test.log"
|
||||
local_file = tmp_path / "dummy.txt"
|
||||
local_file.write_text("hello")
|
||||
|
||||
handlers = [
|
||||
RichHandler(rich_tracebacks=True),
|
||||
logging.FileHandler(log_file, mode='w')
|
||||
]
|
||||
logging.basicConfig(level=logging.INFO, format="%(message)s", handlers=handlers, force=True)
|
||||
|
||||
logging.info("before download")
|
||||
StorageManager.get_local_copy(str(local_file))
|
||||
logging.info("after download")
|
||||
|
||||
with open(log_file) as f:
|
||||
contents = f.read()
|
||||
assert "before download" in contents, "'before download' missing from log file"
|
||||
assert "after download" in contents, "'after download' missing from log file"
|
Loading…
Reference in New Issue
Block a user