From 3305e5c92c596052285018496b10baab41a267c3 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sun, 24 Oct 2010 00:25:27 +0200 Subject: [PATCH] Add functions to add and remove a root log handler. --- linkcheck/configuration/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 19906771..acca9ecf 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -172,19 +172,27 @@ class Configuration (dict): logging.config.fileConfig(filename) if handler is None: handler = ansicolor.ColoredStreamHandler(strm=sys.stderr) - logging.getLogger(LOG_ROOT).addHandler(handler) + self.add_loghandler(handler) self.set_debug(debug) self.status_logger = status_logger + + def set_debug (self, debug): + """Set debugging levels for configured loggers. The argument + is a list of logger names to enable debug for.""" + self.set_loglevel(debug, logging.DEBUG) + + def add_loghandler (self, handler): + """Add log handler to root logger LOG_ROOT and set formatting.""" + logging.getLogger(LOG_ROOT).addHandler(handler) if self['threads'] > 0: format = "%(levelname)s %(threadName)s %(message)s" else: format = "%(levelname)s %(message)s" handler.setFormatter(logging.Formatter(format)) - def set_debug (self, debug): - """Set debugging levels for configured loggers. The argument - is a list of logger names to enable debug for.""" - self.set_loglevel(debug, logging.DEBUG) + def remove_loghandler (self, handler): + """Remove log handler from root logger LOG_ROOT.""" + logging.getLogger(LOG_ROOT).removeHandler(handler) def reset_loglevel (self): """Reset log level to display only warnings and errors."""