Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not configure the root logger. #741

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions tornado/ioloop.py
Expand Up @@ -32,7 +32,6 @@
import errno
import functools
import heapq
import logging
import numbers
import os
import select
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tornado/log.py
Expand Up @@ -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():
Expand Down