]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Suppress tornado's default logging setup if there is any existing logging
authorBen Darnell <ben@bendarnell.com>
Mon, 16 Aug 2010 01:17:42 +0000 (18:17 -0700)
committerBen Darnell <ben@bendarnell.com>
Mon, 16 Aug 2010 01:17:42 +0000 (18:17 -0700)
config, not just --log_file_prefix.

tornado/options.py

index a0bb1a78002672da66686d9ce663992f70bedac8..5b09628b8519c103d45bde933f8038e428c17b43 100644 (file)
@@ -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, "