From 2214650621ee57b4c427bf8b5cab1128eb06db93 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 19 Jun 2016 08:50:55 +0000 Subject: Logger: started logging SQL --- wqflask/utility/logger.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index 81202b05..bc0578c9 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -28,6 +28,7 @@ import logging import string +from inspect import isfunction from utility.tools import LOG_LEVEL class GNLogger: @@ -62,8 +63,10 @@ class GNLogger: self.collect(self.logger.error,*args) def debugf(self,*args): - """Call logging.debug for multiple args""" - self.collect(self.logger.debug,*args) + """Call logging.debug for multiple args lazily""" + if self.logger.getEffectiveLevel() <= 10: + self.debug("Calling debug function!") + self.collectf(self.logger.debug,*args) def sql(self, sqlcommand, fun = None): """Log SQL command, optionally invoking a timed fun""" @@ -73,6 +76,14 @@ class GNLogger: for a in args: fun(a) + def collectf(self,fun,*args): + """Collect arguments and use fun to output one by one""" + for a in args: + if isfunction(a): + fun(a()) + else: + fun(a) + # Get the module logger. You can override log levels at the # module level def getLogger(name, level = None): -- cgit v1.2.3