Show More
@@ -133,6 +133,27 b' class Application(SingletonConfigurable):' | |||
|
133 | 133 | self.log_level = new |
|
134 | 134 | self.log.setLevel(new) |
|
135 | 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 | |
|
156 | ||
|
136 | 157 | # the alias map for configurables |
|
137 | 158 | aliases = Dict({'log-level' : 'Application.log_level'}) |
|
138 | 159 | |
@@ -169,32 +190,11 b' class Application(SingletonConfigurable):' | |||
|
169 | 190 | if self.__class__ not in self.classes: |
|
170 | 191 | self.classes.insert(0, self.__class__) |
|
171 | 192 | |
|
172 | self.init_logging() | |
|
173 | ||
|
174 | 193 | def _config_changed(self, name, old, new): |
|
175 | 194 | SingletonConfigurable._config_changed(self, name, old, new) |
|
176 | 195 | self.log.debug('Config changed:') |
|
177 | 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 | 198 | @catch_config_error |
|
199 | 199 | def initialize(self, argv=None): |
|
200 | 200 | """Do the basic steps to configure me. |
@@ -45,8 +45,6 b' class DummyIPClusterStart(IPClusterStart):' | |||
|
45 | 45 | |
|
46 | 46 | def init_signal(self): |
|
47 | 47 | pass |
|
48 | def init_logging(self): | |
|
49 | pass | |
|
50 | 48 | def reinit_logging(self): |
|
51 | 49 | pass |
|
52 | 50 |
@@ -390,7 +390,6 b' class NotebookApp(BaseIPythonApplication):' | |||
|
390 | 390 | self.cluster_manager.update_profiles() |
|
391 | 391 | |
|
392 | 392 | def init_logging(self): |
|
393 | super(NotebookApp, self).init_logging() | |
|
394 | 393 | # This prevents double log messages because tornado use a root logger that |
|
395 | 394 | # self.log is a child of. The logging module dipatches log messages to a log |
|
396 | 395 | # and all of its ancenstors until propagate is set to False. |
@@ -493,6 +492,7 b' class NotebookApp(BaseIPythonApplication):' | |||
|
493 | 492 | |
|
494 | 493 | @catch_config_error |
|
495 | 494 | def initialize(self, argv=None): |
|
495 | self.init_logging() | |
|
496 | 496 | super(NotebookApp, self).initialize(argv) |
|
497 | 497 | self.init_configurables() |
|
498 | 498 | self.init_webapp() |
@@ -175,9 +175,12 b' class BaseParallelApplication(BaseIPythonApplication):' | |||
|
175 | 175 | else: |
|
176 | 176 | open_log_file = None |
|
177 | 177 | if open_log_file is not None: |
|
178 |
self.log. |
|
|
178 | while self.log.handlers: | |
|
179 | self.log.removeHandler(self.log.handlers[0]) | |
|
179 | 180 | self._log_handler = logging.StreamHandler(open_log_file) |
|
180 | 181 | self.log.addHandler(self._log_handler) |
|
182 | else: | |
|
183 | self._log_handler = self.log.handlers[0] | |
|
181 | 184 | # Add timestamps to log format: |
|
182 | 185 | self._log_formatter = logging.Formatter("%(asctime)s.%(msecs).03d [%(name)s] %(message)s", |
|
183 | 186 | datefmt="%Y-%m-%d %H:%M:%S") |
@@ -434,11 +434,9 b' class IPControllerApp(BaseParallelApplication):' | |||
|
434 | 434 | lsock = context.socket(zmq.PUB) |
|
435 | 435 | lsock.connect(self.log_url) |
|
436 | 436 | handler = PUBHandler(lsock) |
|
437 | self.log.removeHandler(self._log_handler) | |
|
438 | 437 | handler.root_topic = 'controller' |
|
439 | 438 | handler.setLevel(self.log_level) |
|
440 | 439 | self.log.addHandler(handler) |
|
441 | self._log_handler = handler | |
|
442 | 440 | |
|
443 | 441 | @catch_config_error |
|
444 | 442 | def initialize(self, argv=None): |
@@ -288,11 +288,9 b' class IPEngineApp(BaseParallelApplication):' | |||
|
288 | 288 | context = self.engine.context |
|
289 | 289 | lsock = context.socket(zmq.PUB) |
|
290 | 290 | lsock.connect(self.log_url) |
|
291 | self.log.removeHandler(self._log_handler) | |
|
292 | 291 | handler = EnginePUBHandler(self.engine, lsock) |
|
293 | 292 | handler.setLevel(self.log_level) |
|
294 | 293 | self.log.addHandler(handler) |
|
295 | self._log_handler = handler | |
|
296 | 294 | |
|
297 | 295 | def init_mpi(self): |
|
298 | 296 | global mpi |
General Comments 0
You need to be logged in to leave comments.
Login now