python3 - 2to3 + miscell obvious tweaks
[sfa.git] / sfa / util / sfalogging.py
index a8f88f5..fd1cabf 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
 """
 A reroutable logger that can handle deep tracebacks
@@ -34,7 +34,7 @@ Implementation:
 
 # pylint: disable=c0111, c0103, w1201
 
-from __future__ import print_function
+
 
 import os
 import os.path
@@ -123,7 +123,7 @@ def logging_config(context):
     if context == 'server':
         handlername = 'file'
         filename = '/var/log/sfa.log'
-        level = 'INFO'
+        level = 'DEBUG'
     elif context == 'import':
         handlername = 'file'
         filename = '/var/log/sfa-import.log'
@@ -140,7 +140,7 @@ def logging_config(context):
         print("Cannot configure logging - exiting")
         exit(1)
 
-    return {
+    config = {
         'version': 1,
         # IMPORTANT: we may be imported by something else, so:
         'disable_existing_loggers': False,
@@ -151,19 +151,9 @@ def logging_config(context):
                            '%(filename)s:%(lineno)d %(message)s'),
             },
         },
+        # fill in later with just the one needed
+        # otherwise a dummy 'ignored' file gets created
         'handlers': {
-            'file': {
-                'filename': filename,
-                'level': level,
-                # not using RotatingFileHandler for this first version
-                'class': 'logging.FileHandler',
-                'formatter': 'standard',
-            },
-            'stdout': {
-                'level': level,
-                'class': 'logging.StreamHandler',
-                'formatter': 'standard',
-            },
         },
         'loggers': {
             'sfa': {
@@ -173,6 +163,24 @@ def logging_config(context):
             },
         },
     }
+    if handlername == 'stdout':
+        config['handlers']['stdout'] = {
+            'level': level,
+            'formatter': 'standard',
+            'class': 'logging.StreamHandler',
+        }
+    else:
+        config['handlers']['file'] = {
+            'filename': filename,
+            'level': level,
+            'formatter': 'standard',
+            'class': 'logging.handlers.TimedRotatingFileHandler',
+            # every monday and during 3 months
+            'when': 'w0',
+            'interval': 1,
+            'backupCount': 12,
+        }
+    return config
 
 
 logger = logging.getLogger('sfa')