From 2792557c4f978e156a9e92745c4d2c4b3759b507 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 18 Jun 2016 13:04:46 +0000 Subject: Logger: create stub so we can have multiple arguments to log functions --- wqflask/utility/logger.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index 479f6c46..f0790ab1 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -27,16 +27,45 @@ # We'll add more overrides soon. import logging +import string from utility.tools import LOG_LEVEL +class GNLogger: + """A stub for multiple parameter logging""" + + def __init__(self,name): + self.logger = logging.getLogger(name) + + def setLevel(self,value): + self.logger.setLevel(value) + + def debug(self,*args): + self.collect(self.logger.debug,*args) + + def info(self,*args): + self.collect(self.logger.info,*args) + + def warning(self,*args): + self.collect(self.logger.warning,*args) + self.logger.warning(self.collect(*args)) + + def error(self,*args): + self.collect(self.logger.error,*args) + + def collect(self,fun,*args): + for a in args: + fun(a) + # Get the module logger. You can override log levels at the # module level def getLogger(name, level = None): - logger = logging.getLogger(name) + gnlogger = GNLogger(name) + logger = gnlogger.logger + if level: logger.setLevel(level) else: logger.setLevel(LOG_LEVEL) - logger.debug("Log "+name+" at level "+logging.getLevelName(logger.getEffectiveLevel())) - return logger + logger.debug("Log level of "+name+" set to "+logging.getLevelName(logger.getEffectiveLevel())) + return gnlogger -- cgit v1.2.3