]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Move _setup_logging to BaseIOLoop and use it in asyncio and twisted implementations.
authorBen Darnell <ben@bendarnell.com>
Mon, 6 Jan 2014 23:51:07 +0000 (18:51 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 6 Jan 2014 23:51:07 +0000 (18:51 -0500)
tornado/ioloop.py
tornado/platform/asyncio.py
tornado/platform/twisted.py

index 7463882f94e1f7025ac3932df7ad684168e3b472..e7b84dd7c702b29b7d2f16847ea7264c9fd2d008 100644 (file)
@@ -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:
index 87f28044c6fac5369339e219c423aee7f8b61afe..bc5c2f27d3f1266ed869509595a090c697f02cd4 100644 (file)
@@ -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):
index 86ef71b903f61d591c6889ac27113edb19da05d2..0c8a3105c732ef2ea902d8df673258e2b2d7c78c 100644 (file)
@@ -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):