diff options
author | Pjotr Prins | 2016-06-24 06:51:28 +0000 |
---|---|---|
committer | Pjotr Prins | 2016-06-24 06:51:28 +0000 |
commit | 764136ff18bd355f7b9dbe91f870919b0a17322e (patch) | |
tree | 2636b5c0d68d38e391476b4723a6f005d536b5c8 /wqflask/utility/logger.py | |
parent | 923e94c39f5768f836dbf5fc29b0186c13ccc86b (diff) | |
download | genenetwork2-764136ff18bd355f7b9dbe91f870919b0a17322e.tar.gz |
Log: and document SQL calls
Diffstat (limited to 'wqflask/utility/logger.py')
-rw-r--r-- | wqflask/utility/logger.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index c62ea2fe..86ee1c52 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -32,7 +32,7 @@ from inspect import isfunction from pprint import pformat as pf from inspect import stack -from utility.tools import LOG_LEVEL, LOG_SQL, LOG_FORMAT +from utility.tools import LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_SQL, LOG_FORMAT class GNLogger: """A logger class with some additional functionality, such as @@ -48,9 +48,13 @@ class GNLogger: """Set the undelying log level""" self.logger.setLevel(value) - def debug(self,*args): - """Call logging.debug for multiple args""" - self.collect(self.logger.debug,*args) + def debug(self,level=0,*args): + """Call logging.debug for multiple args. Use level=num to filter on +LOG_LEVEL_DEBUG. + + """ + if level <= LOG_LEVEL_DEBUG: + self.collect(self.logger.debug,*args) def info(self,*args): """Call logging.info for multiple args""" @@ -71,16 +75,20 @@ class GNLogger: if self.logger.getEffectiveLevel() < 30: self.collectf(self.logger.debug,*args) - def debugf(self,*args): + def debugf(self,level=0,*args): """Call logging.debug for multiple args lazily""" # only evaluate function when logging - if self.logger.getEffectiveLevel() < 20: - self.collectf(self.logger.debug,*args) + if level <= LOG_LEVEL_DEBUG: + if self.logger.getEffectiveLevel() < 20: + self.collectf(self.logger.debug,*args) def sql(self, sqlcommand, fun = None): """Log SQL command, optionally invoking a timed fun""" if LOG_SQL: - self.info(stack()[1][3],sqlcommand) + caller = stack()[1][3] + if caller in ['fetchone','fetch1','fetchall']: + caller = stack()[2][3] + self.info(caller,sqlcommand) if fun: result = fun(sqlcommand) if LOG_SQL: |