comparison src/core/log_config.py @ 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 ee450d7c88a7
children 08f50fdac21b
comparison
equal deleted inserted replaced
1120:d1f6b927131e 1121:64ff259d3cbb
187 addObserver = self.twisted_log.addObserver 187 addObserver = self.twisted_log.addObserver
188 188
189 if C.LOG_OPT_OUTPUT_DEFAULT in log.handlers: 189 if C.LOG_OPT_OUTPUT_DEFAULT in log.handlers:
190 # default output is already managed, we just add output to stdout if we are in debug or nodaemon mode 190 # default output is already managed, we just add output to stdout if we are in debug or nodaemon mode
191 191
192 def postOptions(options): # called after options are parsed
193 if options.get('nodaemon', False) or options.get('debug', False):
194 addObserver(self.twisted_log.FileLogObserver(sys.stdout).emit)
195
192 # XXX: this hack is to know if we are in debug or nodaemon mode 196 # XXX: this hack is to know if we are in debug or nodaemon mode
193 # any better method welcomed 197 # any better method welcomed
194 from twisted.scripts import twistd 198 from twisted.scripts import twistd
195 options = twistd.ServerOptions() 199 # we monkey patch ServerOptions to be sure options.get is done after options are fully parsed
196 options.parseOptions() 200 # XXX: only works with twistd plugins, not with .tac files !
197 if options.get('nodaemon', False) or options.get('debug', False): 201 twistd.ServerOptions.postOptions = postOptions
198 addObserver(self.twisted_log.FileLogObserver(sys.stdout).emit)
199 else: 202 else:
200 # \\default is not in the output, so we remove current observers 203 # \\default is not in the output, so we remove current observers
201 self.cleared_observers = self.log_publisher.observers 204 self.cleared_observers = self.log_publisher.observers
202 self.observers.clear() 205 self.observers.clear()
203 del self.log_publisher.observers[:] 206 del self.log_publisher.observers[:]