diff --git a/tornado/ioloop.py b/tornado/ioloop.py index dd9639c056..b87ff70cef 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -32,7 +32,6 @@ import errno import functools import heapq -import logging import numbers import os import select @@ -42,7 +41,7 @@ import traceback from tornado.concurrent import Future, TracebackFuture -from tornado.log import app_log, gen_log +from tornado.log import app_log, gen_log, check_log_handlers from tornado import stack_context from tornado.util import Configurable @@ -541,15 +540,7 @@ def set_blocking_signal_threshold(self, seconds, action): action if action is not None else signal.SIG_DFL) def start(self): - if not logging.getLogger().handlers: - # 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. - logging.basicConfig() + check_log_handlers() if self._stopped: self._stopped = False return diff --git a/tornado/log.py b/tornado/log.py index fa11f37953..695dd44e44 100644 --- a/tornado/log.py +++ b/tornado/log.py @@ -49,6 +49,27 @@ gen_log = logging.getLogger("tornado.general") +def _basic_config(logger): + logger.addHandler(logging.StreamHandler()) + + +def check_log_handlers(): + '''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. + ''' + for parent in (None, 'tornado'): + if logging.getLogger(parent).handlers: + return + for logger in (access_log, app_log, gen_log): + if not logger.handlers: + _basic_config(logger) + + def _stderr_supports_color(): color = False if curses and sys.stderr.isatty():