From: Ben Darnell Date: Mon, 16 Aug 2010 01:17:42 +0000 (-0700) Subject: Suppress tornado's default logging setup if there is any existing logging X-Git-Tag: v1.1.0~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51d6ba42dd0cd260c28d6feec1357712201f76f3;p=thirdparty%2Ftornado.git Suppress tornado's default logging setup if there is any existing logging config, not just --log_file_prefix. --- diff --git a/tornado/options.py b/tornado/options.py index a0bb1a780..5b09628b8 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -304,8 +304,17 @@ class Error(Exception): def enable_pretty_logging(): """Turns on formatted logging output as configured.""" + root_logger = logging.getLogger() + if options.log_file_prefix: + channel = logging.handlers.RotatingFileHandler( + filename=options.log_file_prefix, + maxBytes=options.log_file_max_size, + backupCount=options.log_file_num_backups) + channel.setFormatter(_LogFormatter(color=False)) + root_logger.addHandler(channel) + if (options.log_to_stderr or - (options.log_to_stderr is None and not options.log_file_prefix)): + (options.log_to_stderr is None and not root_logger.handlers)): # Set up color if we are in a tty and curses is installed color = False if curses and sys.stderr.isatty(): @@ -317,15 +326,8 @@ def enable_pretty_logging(): pass channel = logging.StreamHandler() channel.setFormatter(_LogFormatter(color=color)) - logging.getLogger().addHandler(channel) + root_logger.addHandler(channel) - if options.log_file_prefix: - channel = logging.handlers.RotatingFileHandler( - filename=options.log_file_prefix, - maxBytes=options.log_file_max_size, - backupCount=options.log_file_num_backups) - channel.setFormatter(_LogFormatter(color=False)) - logging.getLogger().addHandler(channel) class _LogFormatter(logging.Formatter): @@ -374,7 +376,8 @@ define("logging", default="info", metavar="info|warning|error|none") define("log_to_stderr", type=bool, default=None, help=("Send log output to stderr (colorized if possible). " - "By default use stderr if --log_file_prefix is not set.")) + "By default use stderr if --log_file_prefix is not set and " + "no other logging is configured.")) define("log_file_prefix", type=str, default=None, metavar="PATH", help=("Path prefix for log files. " "Note that if you are running multiple tornado processes, "