mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +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
37
src/log.py
37
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):
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user