From 9483d0a50e50753c8b17f7696876fba9bebd27bf Mon Sep 17 00:00:00 2001 From: "Matthew D. Scholefield" Date: Fri, 29 Sep 2017 01:52:01 -0500 Subject: [PATCH] Unroll loop to explicitly show attributes in LOG This allows IDEs to use autocomplete on the LOG class --- mycroft/util/log.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mycroft/util/log.py b/mycroft/util/log.py index dc5a567207..56e31f5eb7 100644 --- a/mycroft/util/log.py +++ b/mycroft/util/log.py @@ -28,6 +28,15 @@ def getLogger(name="MYCROFT"): return logging.getLogger(name) +def _make_log_method(fn): + @classmethod + def method(cls, *args, **kwargs): + cls._log(fn, *args, **kwargs) + + method.__func__.__doc__ = fn.__doc__ + return method + + class LOG: """ Custom logger class that acts like logging.Logger @@ -42,6 +51,14 @@ class LOG: handler = None level = None + # Copy actual logging methods from logging.Logger + # Usage: LOG.debug(message) + debug = _make_log_method(logging.Logger.debug) + info = _make_log_method(logging.Logger.info) + warning = _make_log_method(logging.Logger.warning) + error = _make_log_method(logging.Logger.error) + exception = _make_log_method(logging.Logger.exception) + @classmethod def init(cls): sys_config = '/etc/mycroft/mycroft.conf' @@ -55,17 +72,6 @@ class LOG: cls.handler.setFormatter(formatter) cls.create_logger('') # Enables logging in external modules - def make_method(fn): - @classmethod - def method(cls, *args, **kwargs): - cls._log(fn, *args, **kwargs) - method.__func__.__doc__ = fn.__doc__ - return method - - # Copy actual logging methods from logging.Logger - for name in ['debug', 'info', 'warning', 'error', 'exception']: - setattr(cls, name, make_method(getattr(logging.Logger, name))) - @classmethod def create_logger(cls, name): l = logging.getLogger(name)