skytools.scripting: fix fileConfig on python 2.5
authorMarko Kreen <markokr@gmail.com>
Thu, 24 Nov 2011 09:08:54 +0000 (11:08 +0200)
committerMarko Kreen <markokr@gmail.com>
Thu, 24 Nov 2011 09:08:54 +0000 (11:08 +0200)
There is no disable_existing_loggers argument so
we need manually enable all loggers again.

python/skytools/scripting.py

index 48672620f0670cbae817d636db1ddd1090a8fbe5..cd79bf2d5ed5795984683f2d73317722208b1bae 100644 (file)
@@ -121,6 +121,21 @@ def run_single_process(runnable, daemon, pidfile):
 _log_config_done = 0
 _log_init_done = {}
 
+def _load_log_config(fn, defs):
+    """Fixed fileConfig."""
+
+    # Work around fileConfig default behaviour to disable
+    # not only old handlers on load (which slightly makes sense)
+    # but also old logger objects (which does not make sense).
+
+    if sys.hexversion >= 0x2060000:
+        logging.config.fileConfig(fn, defs, False)
+    else:
+        logging.config.fileConfig(fn, defs)
+        root = logging.getLogger()
+        for lg in root.manager.loggerDict.values():
+            lg.disabled = 0
+
 def _init_log(job_name, service_name, cf, log_level, is_daemon):
     """Logging setup happens here."""
     global _log_init_done, _log_config_done
@@ -147,7 +162,7 @@ def _init_log(job_name, service_name, cf, log_level, is_daemon):
             fn = os.path.expanduser(fn)
             if os.path.isfile(fn):
                 defs = {'job_name': job_name, 'service_name': service_name}
-                logging.config.fileConfig(fn, defs, False)
+                _load_log_config(fn, defs)
                 got_skylog = 1
                 break
         _log_config_done = 1