fix: prevent logging config clobbering (#10133)

Previous behavior: loading this repository with `torch.hub.load` clobbers the existing logging configuration by modifying the root logger's configuration.
New behavior: loading this repository with `torch.hub.load` only clobbers the logging configuration for logger `yolov5` and its descendants.

Signed-off-by: Ryan Echols <ryan@shadylakemedia.com>

Signed-off-by: Ryan Echols <ryan@shadylakemedia.com>
pull/10166/head^2
Ryan Echols 2022-11-16 08:09:30 -07:00 committed by GitHub
parent 5e03f5fc8c
commit 166b9f2fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -126,8 +126,9 @@ def set_logging(name=None, verbose=VERBOSE):
log.addHandler(handler)
set_logging() # run before defining LOGGER
LOGGER = logging.getLogger("yolov5") # define globally (used in train.py, val.py, detect.py, etc.)
logger_name = "yolov5"
set_logging(logger_name) # run before defining LOGGER
LOGGER = logging.getLogger(logger_name) # define globally (used in train.py, val.py, detect.py, etc.)
if platform.system() == 'Windows':
for fn in LOGGER.info, LOGGER.warning:
setattr(LOGGER, fn.__name__, lambda x: fn(emojis(x))) # emoji safe logging