Changeset View
Changeset View
Standalone View
Standalone View
pykolab/logger.py
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | """ | ||||
Custom LoggingAdapter to log Wallace mail message Queue ID | Custom LoggingAdapter to log Wallace mail message Queue ID | ||||
""" | """ | ||||
def process(self, msg, kwargs): | def process(self, msg, kwargs): | ||||
return '%s %s' % (self.extra['qid'], msg), kwargs | return '%s %s' % (self.extra['qid'], msg), kwargs | ||||
# Required for python3 compat because logger adapter now has a native debug function. | # Required for python3 compat because logger adapter now has a native debug function. | ||||
def debug(self, msg, level=1, *args, **kw): | def debug(self, msg, *args, **kw): | ||||
return self.logger.debug(msg, level, args, kw) | return self.logger.debug(msg, args, kw) | ||||
class Logger(logging.Logger): | class Logger(logging.Logger): | ||||
""" | """ | ||||
The PyKolab version of a logger. | The PyKolab version of a logger. | ||||
This class wraps the Python native logging library, adding to the | This class wraps the Python native logging library, adding to the | ||||
loglevel capabilities, a debuglevel capability. | loglevel capabilities, a debuglevel capability. | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | def __init__(self, *args, **kw): | ||||
except IOError: | except IOError: | ||||
pass | pass | ||||
def remove_stdout_handler(self): | def remove_stdout_handler(self): | ||||
if not self.fork: | if not self.fork: | ||||
self.console_stdout.close() | self.console_stdout.close() | ||||
self.removeHandler(self.console_stdout) | self.removeHandler(self.console_stdout) | ||||
# pylint: disable=arguments-differ | def debug(self, msg, *args, **kw): | ||||
# pylint: disable=keyword-arg-before-vararg | |||||
def debug(self, msg, level=1, *args, **kw): | |||||
self.setLevel(self.loglevel) | self.setLevel(self.loglevel) | ||||
# Work around other applications not using various levels of debugging | # Work around other applications not using various levels of debugging | ||||
if not self.name.startswith('pykolab') and self.debuglevel != 9: | if not self.name.startswith('pykolab') and self.debuglevel != 9: | ||||
return | return | ||||
level = kw.get('level', 1) | |||||
if level <= self.debuglevel: | if level <= self.debuglevel: | ||||
self.log(logging.DEBUG, msg) | self.log(logging.DEBUG, msg) | ||||
logging.setLoggerClass(Logger) | logging.setLoggerClass(Logger) |