Unroll loop to explicitly show attributes in LOG

This allows IDEs to use autocomplete on the LOG class
pull/1120/head
Matthew D. Scholefield 2017-09-29 01:52:01 -05:00
parent 4b4a48f796
commit 9483d0a50e
1 changed files with 17 additions and 11 deletions

View File

@ -28,6 +28,15 @@ def getLogger(name="MYCROFT"):
return logging.getLogger(name) 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: class LOG:
""" """
Custom logger class that acts like logging.Logger Custom logger class that acts like logging.Logger
@ -42,6 +51,14 @@ class LOG:
handler = None handler = None
level = 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 @classmethod
def init(cls): def init(cls):
sys_config = '/etc/mycroft/mycroft.conf' sys_config = '/etc/mycroft/mycroft.conf'
@ -55,17 +72,6 @@ class LOG:
cls.handler.setFormatter(formatter) cls.handler.setFormatter(formatter)
cls.create_logger('') # Enables logging in external modules 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 @classmethod
def create_logger(cls, name): def create_logger(cls, name):
l = logging.getLogger(name) l = logging.getLogger(name)