diff --git a/ohmpi/logging_setup.py b/ohmpi/logging_setup.py index e6bb9b87bfedfdafed70851bafceefa969f53132..e2606b024a70b57843cf8ef2890d24b30c13afc7 100644 --- a/ohmpi/logging_setup.py +++ b/ohmpi/logging_setup.py @@ -10,7 +10,7 @@ import sys from termcolor import colored -def add_logging_level(levelName, levelNum, methodName=None): +def add_logging_level(level_name, level_num, method_name=None): """ Comprehensively adds a new logging level to the `logging` module and the currently configured logging class. @@ -31,35 +31,35 @@ def add_logging_level(levelName, levelNum, methodName=None): ------- >>> add_logging_level('TRACE', logging.DEBUG - 5) >>> logging.getLogger(__name__).setLevel("TRACE") - >>> logging.getLogger(__name__).trace('that worked') - >>> logging.trace('so did this') - >>> logging.TRACE - 5 + >>> logging.getLogger(__name__).trace('that worked') # noqa + >>> logging.trace('so did this') # noqa + >>> logging.TRACE # noqa """ - if not methodName: - methodName = levelName.lower() + if not method_name: + method_name = level_name.lower() - if hasattr(logging, levelName): - raise AttributeError('{} already defined in logging module'.format(levelName)) - if hasattr(logging, methodName): - raise AttributeError('{} already defined in logging module'.format(methodName)) - if hasattr(logging.getLoggerClass(), methodName): - raise AttributeError('{} already defined in logger class'.format(methodName)) + if hasattr(logging, level_name): + raise AttributeError('{} already defined in logging module'.format(level_name)) + if hasattr(logging, method_name): + raise AttributeError('{} already defined in logging module'.format(method_name)) + if hasattr(logging.getLoggerClass(), method_name): + raise AttributeError('{} already defined in logger class'.format(method_name)) # This method was inspired by the answers to Stack Overflow post # http://stackoverflow.com/q/2183233/2988730, especially # http://stackoverflow.com/a/13638084/2988730 - def logForLevel(self, message, *args, **kwargs): - if self.isEnabledFor(levelNum): - self._log(levelNum, message, args, **kwargs) - def logToRoot(message, *args, **kwargs): - logging.log(levelNum, message, *args, **kwargs) + def log_for_level(self, message, *args, **kwargs): + if self.isEnabledFor(level_num): + self._log(level_num, message, args, **kwargs) - logging.addLevelName(levelNum, levelName) - setattr(logging, levelName, levelNum) - setattr(logging.getLoggerClass(), methodName, logForLevel) - setattr(logging, methodName, logToRoot) + def log_to_root(message, *args, **kwargs): + logging.log(level_num, message, *args, **kwargs) + + logging.addLevelName(level_num, level_name) + setattr(logging, level_name, level_num) + setattr(logging.getLoggerClass(), method_name, log_for_level) + setattr(logging, method_name, log_to_root) def create_stdout_logger(name): @@ -76,7 +76,7 @@ def create_stdout_logger(name): def setup_loggers(mqtt=True): - add_logging_level('EVENT', logging.INFO + 1) # TODO : check if we should set the level to DEBUG... + add_logging_level('EVENT', logging.DEBUG + 1) # TODO : check if we should set the level to DEBUG... msg = '' # Message logging setup log_path = path.join(path.dirname(__file__), 'logs')