about summary refs log tree commit diff
path: root/wqflask/utility
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/utility')
-rw-r--r--wqflask/utility/logger.py24
-rw-r--r--wqflask/utility/tools.py13
2 files changed, 25 insertions, 12 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:
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 93b1fa51..bb8241f5 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -43,12 +43,13 @@ def get_setting(command_id,guess=None):
     # ---- Check whether environment exists
     logger.debug("Looking for "+command_id+"\n")
     command = value(os.environ.get(command_id))
-    if command == None or command == "":
+    if command is None or command == "":
         # ---- Check whether setting exists in app
         command = value(app.config.get(command_id))
-        if command == None:
+        if command is None:
             command = value(guess)
-            if command == None or command == "":
+            if command is None or command == "":
+                print command
                 raise Exception(command_id+' setting unknown or faulty (update default_settings.py?).')
     logger.debug("Set "+command_id+"="+str(command))
     return command
@@ -61,7 +62,11 @@ def get_setting_bool(id):
 
 def get_setting_int(id):
     v = get_setting(id)
-    return int(v)
+    if isinstance(v, str):
+        return int(v)
+    if v is None:
+        return 0
+    return v
 
 def valid_bin(bin):
     if os.path.islink(bin) or valid_file(bin):