clearml-agent/clearml_agent/backend_config/log.py

31 lines
851 B
Python
Raw Normal View History

2019-10-25 19:28:44 +00:00
import logging.config
from pathlib2 import Path
def logger(path=None):
2020-12-22 21:00:57 +00:00
name = "clearml"
2019-10-25 19:28:44 +00:00
if path:
p = Path(path)
module = (p.parent if p.stem.startswith('_') else p).stem
2020-12-22 21:00:57 +00:00
name = "clearml.%s" % module
2019-10-25 19:28:44 +00:00
return logging.getLogger(name)
def initialize(logging_config=None, extra=None):
if extra is not None:
from logging import Logger
class _Logger(Logger):
__extra = extra.copy()
def _log(self, level, msg, args, exc_info=None, extra=None, **kwargs):
extra = extra or {}
extra.update(self.__extra)
super(_Logger, self)._log(level, msg, args, exc_info=exc_info, extra=extra, **kwargs)
Logger.manager.loggerClass = _Logger
if logging_config is not None:
logging.config.dictConfig(dict(logging_config))