From: Ben Darnell Date: Mon, 6 Jan 2014 23:51:07 +0000 (-0500) Subject: Move _setup_logging to BaseIOLoop and use it in asyncio and twisted implementations. X-Git-Tag: v3.2.0b2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a2460caf390445f28779e9058b3e822e0934ad5;p=thirdparty%2Ftornado.git Move _setup_logging to BaseIOLoop and use it in asyncio and twisted implementations. --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 7463882f9..e7b84dd7c 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -301,6 +301,22 @@ class IOLoop(Configurable): """ raise NotImplementedError() + def _setup_logging(self): + """The IOLoop catches and logs exceptions, so it's + important that log output be visible. However, python's + default behavior for non-root loggers (prior to python + 3.2) is to print an unhelpful "no handlers could be + found" message rather than the actual log entry, so we + must explicitly configure logging if we've made it this + far without anything. + + This method should be called from start() in subclasses. + """ + if not any([logging.getLogger().handlers, + logging.getLogger('tornado').handlers, + logging.getLogger('tornado.application').handlers]): + logging.basicConfig() + def stop(self): """Stop the I/O loop. @@ -549,21 +565,6 @@ class PollIOLoop(IOLoop): signal.signal(signal.SIGALRM, action if action is not None else signal.SIG_DFL) - def _setup_logging(self): - """The IOLoop catches and logs exceptions, so it's - important that log output be visible. However, python's - default behavior for non-root loggers (prior to python - 3.2) is to print an unhelpful "no handlers could be - found" message rather than the actual log entry, so we - must explicitly configure logging if we've made it this - far without anything. - - """ - if not any([logging.getLogger().handlers, - logging.getLogger('tornado').handlers, - logging.getLogger('tornado.application').handlers]): - logging.basicConfig() - def start(self): self._setup_logging() if self._stopped: diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 87f28044c..bc5c2f27d 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -88,6 +88,7 @@ class BaseAsyncIOLoop(IOLoop): self.handlers[fd](fd, events) def start(self): + self._setup_logging() self.asyncio_loop.run_forever() def stop(self): diff --git a/tornado/platform/twisted.py b/tornado/platform/twisted.py index 86ef71b90..0c8a3105c 100644 --- a/tornado/platform/twisted.py +++ b/tornado/platform/twisted.py @@ -456,6 +456,7 @@ class TwistedIOLoop(tornado.ioloop.IOLoop): del self.fds[fd] def start(self): + self._setup_logging() self.reactor.run() def stop(self):