src/log.py: Collapse MultiLogger's methods into using __getattr__ to detect what's being called and return the proper function.

This commit is contained in:
James Vega 2006-10-05 18:06:12 +00:00
parent 2636a35b84
commit 664f56a92f

View File

@ -177,33 +177,16 @@ class MultiLogger(object):
def __init__(self, loggers): def __init__(self, loggers):
self.loggers = loggers self.loggers = loggers
def debug(self, msg, *args, **kwargs): def __getattr__(self, attr):
for logger in self.loggers: def f(*args, **kwargs):
logger.debug(msg, *args, **kwargs) for logger in self.loggers:
getattr(logger, attr)(*args, **kwargs)
def info(self, msg, *args, **kwargs): if attr in ('debug', 'info', 'warning', 'error', 'critical',
for logger in self.loggers: 'exception', 'log'):
logger.info(msg, *args, **kwargs) return f
else:
def warning(self, msg, *args, **kwargs): raise AttributeError('%r object has no attribute %r' %
for logger in self.loggers: (self.__class__.__name__, attr))
logger.warning(msg, *args, **kwargs)
def error(self, msg, *args, **kwargs):
for logger in self.loggers:
logger.error(msg, *args, **kwargs)
def critical(self, msg, *args, **kwargs):
for logger in self.loggers:
logger.critical(msg, *args, **kwargs)
def exception(self, msg, *args, **kwargs):
for logger in self.loggers:
logger.exception(msg, *args, **kwargs)
def log(self, level, msg, *args, **kwargs):
for logger in self.loggers:
logger.log(level, msg, *args, **kwargs)
# These are not. # These are not.
logging.setLoggerClass(Logger) logging.setLoggerClass(Logger)