changeset 1121:64ff259d3cbb

core (logging): fixed twisted backend for twistd plugin, /!\ stdout logging in debug/nodaemon mode does'nt work anymore with .tac files.
author Goffi <goffi@goffi.org>
date Sun, 24 Aug 2014 18:44:17 +0200
parents d1f6b927131e
children 9ae01ccf89c1
files src/core/log_config.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/log_config.py	Fri Aug 22 12:31:55 2014 +0200
+++ b/src/core/log_config.py	Sun Aug 24 18:44:17 2014 +0200
@@ -189,13 +189,16 @@
         if C.LOG_OPT_OUTPUT_DEFAULT in log.handlers:
             # default output is already managed, we just add output to stdout if we are in debug or nodaemon mode
 
+            def postOptions(options): # called after options are parsed
+                if options.get('nodaemon', False) or options.get('debug', False):
+                    addObserver(self.twisted_log.FileLogObserver(sys.stdout).emit)
+
             # XXX: this hack is to know if we are in debug or nodaemon mode
             #      any better method welcomed
             from twisted.scripts import twistd
-            options = twistd.ServerOptions()
-            options.parseOptions()
-            if options.get('nodaemon', False) or options.get('debug', False):
-                addObserver(self.twisted_log.FileLogObserver(sys.stdout).emit)
+            # we monkey patch ServerOptions to be sure options.get is done after options are fully parsed
+            # XXX: only works with twistd plugins, not with .tac files !
+            twistd.ServerOptions.postOptions = postOptions
         else:
             # \\default is not in the output, so we remove current observers
             self.cleared_observers = self.log_publisher.observers