diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-09-11 15:25:00 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-12-18 14:00:14 +0200 |
commit | e021ecaa4ff2aeaff4d103d391811fb6c88f68c7 (patch) | |
tree | 9afc2766ce7788f31fa8a578953ae52edad8b7b7 /gbp/log.py | |
parent | 0d864dcc88f2c8686664031fbb5f7b810491aa9d (diff) | |
download | git-buildpackage-e021ecaa4ff2aeaff4d103d391811fb6c88f68c7.tar.gz git-buildpackage-e021ecaa4ff2aeaff4d103d391811fb6c88f68c7.tar.bz2 git-buildpackage-e021ecaa4ff2aeaff4d103d391811fb6c88f68c7.zip |
log: don't initialize handlers in GbpLogger init
Better compatibility with 3rd party modules that have their own logging
initializations.
Change-Id: Ic91ab54c70537061c3e76dd6317ceeec888fab36
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/log.py')
-rw-r--r-- | gbp/log.py | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -96,31 +96,35 @@ class GbpStreamHandler(logging.StreamHandler): class GbpLogger(logging.Logger): """Logger class for git-buildpackage""" - def __init__(self, name, color='auto', *args, **kwargs): + def __init__(self, name, *args, **kwargs): logging.Logger.__init__(self, name, *args, **kwargs) - self._default_handlers = [GbpStreamHandler(sys.stdout, color), - GbpStreamHandler(sys.stderr, color)] - self._default_handlers[0].addFilter(GbpFilter([DEBUG, INFO])) - self._default_handlers[1].addFilter(GbpFilter([WARNING, ERROR, - CRITICAL])) - for hdlr in self._default_handlers: + self.default_handlers = [] + + def init_default_handlers(self, color='auto'): + """Initialize and set default handlers to logger""" + self.default_handlers = [GbpStreamHandler(sys.stdout, color), + GbpStreamHandler(sys.stderr, color)] + self.default_handlers[0].addFilter(GbpFilter([DEBUG, INFO])) + self.default_handlers[1].addFilter(GbpFilter([WARNING, ERROR, + CRITICAL])) + for hdlr in self.default_handlers: self.addHandler(hdlr) # We don't want to propagate as we add our own handlers self.propagate = False def set_color(self, color): """Set/unset colorized output of the default handlers""" - for hdlr in self._default_handlers: + for hdlr in self.default_handlers: hdlr.set_color(color) def set_color_scheme(self, color_scheme={}): """Set the color scheme of the default handlers""" - for hdlr in self._default_handlers: + for hdlr in self.default_handlers: hdlr.set_color_scheme(color_scheme) def set_format(self, fmt): """Set the format of the default handlers""" - for hdlr in self._default_handlers: + for hdlr in self.default_handlers: hdlr.set_format(fmt) @@ -170,7 +174,11 @@ def getLogger(*args, **kwargs): """Gbp-specific function""" if not issubclass(logging.getLoggerClass(), GbpLogger): logging.setLoggerClass(GbpLogger) - return logging.getLogger(*args, **kwargs) + color = kwargs.pop('color') if 'color' in kwargs else 'auto' + logger = logging.getLogger(*args, **kwargs) + if not logger.default_handlers: + logger.init_default_handlers(color) + return logger def setup(color, verbose, color_scheme=""): """Basic logger setup""" |