mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-07 19:49:23 +01:00
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:
parent
2636a35b84
commit
664f56a92f
35
src/log.py
35
src/log.py
@ -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):
|
||||||
|
def f(*args, **kwargs):
|
||||||
for logger in self.loggers:
|
for logger in self.loggers:
|
||||||
logger.debug(msg, *args, **kwargs)
|
getattr(logger, attr)(*args, **kwargs)
|
||||||
|
if attr in ('debug', 'info', 'warning', 'error', 'critical',
|
||||||
def info(self, msg, *args, **kwargs):
|
'exception', 'log'):
|
||||||
for logger in self.loggers:
|
return f
|
||||||
logger.info(msg, *args, **kwargs)
|
else:
|
||||||
|
raise AttributeError('%r object has no attribute %r' %
|
||||||
def warning(self, msg, *args, **kwargs):
|
(self.__class__.__name__, attr))
|
||||||
for logger in self.loggers:
|
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user