about summary refs log tree commit diff
path: root/wqflask/utility/logger.py
diff options
context:
space:
mode:
authorArthur Centeno2021-10-25 21:04:23 +0000
committerArthur Centeno2021-10-25 21:04:23 +0000
commit499a80f138030c4de1629c043c8f9401a99894ea (patch)
tree449dcae965d13f966fb6d52625fbc86661c8c6a0 /wqflask/utility/logger.py
parent6151faa9ea67af4bf4ea95fb681a9dc4319474b6 (diff)
parent700802303e5e8221a9d591ba985d6607aa61e1ce (diff)
downloadgenenetwork2-499a80f138030c4de1629c043c8f9401a99894ea.tar.gz
Merge github.com:genenetwork/genenetwork2 into acenteno
Diffstat (limited to 'wqflask/utility/logger.py')
-rw-r--r--wqflask/utility/logger.py64
1 files changed, 34 insertions, 30 deletions
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py
index 510b1041..d706e32a 100644
--- a/wqflask/utility/logger.py
+++ b/wqflask/utility/logger.py
@@ -35,6 +35,7 @@ import datetime
 
 from utility.tools import LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_SQL
 
+
 class GNLogger:
     """A logger class with some additional functionality, such as
     multiple parameter logging, SQL logging, timing, colors, and lazy
@@ -42,52 +43,52 @@ class GNLogger:
 
     """
 
-    def __init__(self,name):
+    def __init__(self, name):
         self.logger = logging.getLogger(name)
 
-    def setLevel(self,value):
+    def setLevel(self, value):
         """Set the undelying log level"""
         self.logger.setLevel(value)
 
-    def debug(self,*args):
+    def debug(self, *args):
         """Call logging.debug for multiple args. Use (lazy) debugf and
 level=num to filter on LOG_LEVEL_DEBUG.
 
         """
-        self.collect(self.logger.debug,*args)
+        self.collect(self.logger.debug, *args)
 
-    def debug20(self,*args):
+    def debug20(self, *args):
         """Call logging.debug for multiple args. Use level=num to filter on
 LOG_LEVEL_DEBUG (NYI).
 
         """
         if level <= LOG_LEVEL_DEBUG:
             if self.logger.getEffectiveLevel() < 20:
-                self.collect(self.logger.debug,*args)
+                self.collect(self.logger.debug, *args)
 
-    def info(self,*args):
+    def info(self, *args):
         """Call logging.info for multiple args"""
-        self.collect(self.logger.info,*args)
+        self.collect(self.logger.info, *args)
 
-    def warning(self,*args):
+    def warning(self, *args):
         """Call logging.warning for multiple args"""
-        self.collect(self.logger.warning,*args)
+        self.collect(self.logger.warning, *args)
         # self.logger.warning(self.collect(*args))
 
-    def error(self,*args):
+    def error(self, *args):
         """Call logging.error for multiple args"""
         now = datetime.datetime.utcnow()
         time_str = now.strftime('%H:%M:%S UTC %Y%m%d')
-        l = [time_str]+list(args)
-        self.collect(self.logger.error,*l)
+        l = [time_str] + list(args)
+        self.collect(self.logger.error, *l)
 
-    def infof(self,*args):
+    def infof(self, *args):
         """Call logging.info for multiple args lazily"""
         # only evaluate function when logging
         if self.logger.getEffectiveLevel() < 30:
-            self.collectf(self.logger.debug,*args)
+            self.collectf(self.logger.debug, *args)
 
-    def debugf(self,level=0,*args):
+    def debugf(self, level=0, *args):
         """Call logging.debug for multiple args lazily and handle
         LOG_LEVEL_DEBUG correctly
 
@@ -95,38 +96,38 @@ LOG_LEVEL_DEBUG (NYI).
         # only evaluate function when logging
         if level <= LOG_LEVEL_DEBUG:
             if self.logger.getEffectiveLevel() < 20:
-                self.collectf(self.logger.debug,*args)
+                self.collectf(self.logger.debug, *args)
 
-    def sql(self, sqlcommand, fun = None):
+    def sql(self, sqlcommand, fun=None):
         """Log SQL command, optionally invoking a timed fun"""
         if LOG_SQL:
             caller = stack()[1][3]
-            if caller in ['fetchone','fetch1','fetchall']:
+            if caller in ['fetchone', 'fetch1', 'fetchall']:
                 caller = stack()[2][3]
-            self.info(caller,sqlcommand)
+            self.info(caller, sqlcommand)
         if fun:
             result = fun(sqlcommand)
             if LOG_SQL:
                 self.info(result)
             return result
 
-    def collect(self,fun,*args):
+    def collect(self, fun, *args):
         """Collect arguments and use fun to output"""
-        out = "."+stack()[2][3]
+        out = "." + stack()[2][3]
         for a in args:
-            if len(out)>1:
+            if len(out) > 1:
                 out += ": "
             if isinstance(a, str):
                 out = out + a
             else:
-                out = out + pf(a,width=160)
+                out = out + pf(a, width=160)
         fun(out)
 
-    def collectf(self,fun,*args):
+    def collectf(self, fun, *args):
         """Collect arguments and use fun to output one by one"""
-        out = "."+stack()[2][3]
+        out = "." + stack()[2][3]
         for a in args:
-            if len(out)>1:
+            if len(out) > 1:
                 out += ": "
                 if isfunction(a):
                     out += a()
@@ -134,12 +135,14 @@ LOG_LEVEL_DEBUG (NYI).
                     if isinstance(a, str):
                         out = out + a
                     else:
-                        out = out + pf(a,width=160)
+                        out = out + pf(a, width=160)
         fun(out)
 
 # Get the module logger. You can override log levels at the
 # module level
-def getLogger(name, level = None):
+
+
+def getLogger(name, level=None):
     gnlogger = GNLogger(name)
     logger = gnlogger.logger
 
@@ -148,5 +151,6 @@ def getLogger(name, level = None):
     else:
         logger.setLevel(LOG_LEVEL)
 
-    logger.info("Log level of "+name+" set to "+logging.getLevelName(logger.getEffectiveLevel()))
+    logger.info("Log level of " + name + " set to " + \
+                logging.getLevelName(logger.getEffectiveLevel()))
     return gnlogger