##// END OF EJS Templates
move default log setup to _log_default from init_logging...
MinRK -
Show More
@@ -132,6 +132,27 b' class Application(SingletonConfigurable):'
132 new = getattr(logging, new)
132 new = getattr(logging, new)
133 self.log_level = new
133 self.log_level = new
134 self.log.setLevel(new)
134 self.log.setLevel(new)
135
136 log = Instance(logging.Logger)
137 def _log_default(self):
138 """Start logging for this application.
139
140 The default is to log to stdout using a StreaHandler. The log level
141 starts at loggin.WARN, but this can be adjusted by setting the
142 ``log_level`` attribute.
143 """
144 log = logging.getLogger(self.__class__.__name__)
145 log.setLevel(self.log_level)
146 if sys.executable.endswith('pythonw.exe'):
147 # this should really go to a file, but file-logging is only
148 # hooked up in parallel applications
149 _log_handler = logging.StreamHandler(open(os.devnull, 'w'))
150 else:
151 _log_handler = logging.StreamHandler()
152 _log_formatter = logging.Formatter("[%(name)s] %(message)s")
153 _log_handler.setFormatter(_log_formatter)
154 log.addHandler(_log_handler)
155 return log
135
156
136 # the alias map for configurables
157 # the alias map for configurables
137 aliases = Dict({'log-level' : 'Application.log_level'})
158 aliases = Dict({'log-level' : 'Application.log_level'})
@@ -169,32 +190,11 b' class Application(SingletonConfigurable):'
169 if self.__class__ not in self.classes:
190 if self.__class__ not in self.classes:
170 self.classes.insert(0, self.__class__)
191 self.classes.insert(0, self.__class__)
171
192
172 self.init_logging()
173
174 def _config_changed(self, name, old, new):
193 def _config_changed(self, name, old, new):
175 SingletonConfigurable._config_changed(self, name, old, new)
194 SingletonConfigurable._config_changed(self, name, old, new)
176 self.log.debug('Config changed:')
195 self.log.debug('Config changed:')
177 self.log.debug(repr(new))
196 self.log.debug(repr(new))
178
197
179 def init_logging(self):
180 """Start logging for this application.
181
182 The default is to log to stdout using a StreaHandler. The log level
183 starts at loggin.WARN, but this can be adjusted by setting the
184 ``log_level`` attribute.
185 """
186 self.log = logging.getLogger(self.__class__.__name__)
187 self.log.setLevel(self.log_level)
188 if sys.executable.endswith('pythonw.exe'):
189 # this should really go to a file, but file-logging is only
190 # hooked up in parallel applications
191 self._log_handler = logging.StreamHandler(open(os.devnull, 'w'))
192 else:
193 self._log_handler = logging.StreamHandler()
194 self._log_formatter = logging.Formatter("[%(name)s] %(message)s")
195 self._log_handler.setFormatter(self._log_formatter)
196 self.log.addHandler(self._log_handler)
197
198 @catch_config_error
198 @catch_config_error
199 def initialize(self, argv=None):
199 def initialize(self, argv=None):
200 """Do the basic steps to configure me.
200 """Do the basic steps to configure me.
@@ -45,8 +45,6 b' class DummyIPClusterStart(IPClusterStart):'
45
45
46 def init_signal(self):
46 def init_signal(self):
47 pass
47 pass
48 def init_logging(self):
49 pass
50 def reinit_logging(self):
48 def reinit_logging(self):
51 pass
49 pass
52
50
@@ -390,7 +390,6 b' class NotebookApp(BaseIPythonApplication):'
390 self.cluster_manager.update_profiles()
390 self.cluster_manager.update_profiles()
391
391
392 def init_logging(self):
392 def init_logging(self):
393 super(NotebookApp, self).init_logging()
394 # This prevents double log messages because tornado use a root logger that
393 # This prevents double log messages because tornado use a root logger that
395 # self.log is a child of. The logging module dipatches log messages to a log
394 # self.log is a child of. The logging module dipatches log messages to a log
396 # and all of its ancenstors until propagate is set to False.
395 # and all of its ancenstors until propagate is set to False.
@@ -493,6 +492,7 b' class NotebookApp(BaseIPythonApplication):'
493
492
494 @catch_config_error
493 @catch_config_error
495 def initialize(self, argv=None):
494 def initialize(self, argv=None):
495 self.init_logging()
496 super(NotebookApp, self).initialize(argv)
496 super(NotebookApp, self).initialize(argv)
497 self.init_configurables()
497 self.init_configurables()
498 self.init_webapp()
498 self.init_webapp()
@@ -175,9 +175,12 b' class BaseParallelApplication(BaseIPythonApplication):'
175 else:
175 else:
176 open_log_file = None
176 open_log_file = None
177 if open_log_file is not None:
177 if open_log_file is not None:
178 self.log.removeHandler(self._log_handler)
178 while self.log.handlers:
179 self.log.removeHandler(self.log.handlers[0])
179 self._log_handler = logging.StreamHandler(open_log_file)
180 self._log_handler = logging.StreamHandler(open_log_file)
180 self.log.addHandler(self._log_handler)
181 self.log.addHandler(self._log_handler)
182 else:
183 self._log_handler = self.log.handlers[0]
181 # Add timestamps to log format:
184 # Add timestamps to log format:
182 self._log_formatter = logging.Formatter("%(asctime)s.%(msecs).03d [%(name)s] %(message)s",
185 self._log_formatter = logging.Formatter("%(asctime)s.%(msecs).03d [%(name)s] %(message)s",
183 datefmt="%Y-%m-%d %H:%M:%S")
186 datefmt="%Y-%m-%d %H:%M:%S")
@@ -434,11 +434,9 b' class IPControllerApp(BaseParallelApplication):'
434 lsock = context.socket(zmq.PUB)
434 lsock = context.socket(zmq.PUB)
435 lsock.connect(self.log_url)
435 lsock.connect(self.log_url)
436 handler = PUBHandler(lsock)
436 handler = PUBHandler(lsock)
437 self.log.removeHandler(self._log_handler)
438 handler.root_topic = 'controller'
437 handler.root_topic = 'controller'
439 handler.setLevel(self.log_level)
438 handler.setLevel(self.log_level)
440 self.log.addHandler(handler)
439 self.log.addHandler(handler)
441 self._log_handler = handler
442
440
443 @catch_config_error
441 @catch_config_error
444 def initialize(self, argv=None):
442 def initialize(self, argv=None):
@@ -288,11 +288,9 b' class IPEngineApp(BaseParallelApplication):'
288 context = self.engine.context
288 context = self.engine.context
289 lsock = context.socket(zmq.PUB)
289 lsock = context.socket(zmq.PUB)
290 lsock.connect(self.log_url)
290 lsock.connect(self.log_url)
291 self.log.removeHandler(self._log_handler)
292 handler = EnginePUBHandler(self.engine, lsock)
291 handler = EnginePUBHandler(self.engine, lsock)
293 handler.setLevel(self.log_level)
292 handler.setLevel(self.log_level)
294 self.log.addHandler(handler)
293 self.log.addHandler(handler)
295 self._log_handler = handler
296
294
297 def init_mpi(self):
295 def init_mpi(self):
298 global mpi
296 global mpi
General Comments 0
You need to be logged in to leave comments. Login now