Silence testserver logs when tests are run in non-verbose mode

The console output from testserver.py, chromiumsync.py and xmppserver.py during sync integration test runs is pretty chatty, and could do with being disabled by default. In addition, testserver.py spits out logs for non-sync tests even when the tests are run in non-verbose mode.

This patch adds a switch to testserver.py called "log-to-console", and ties it up to the logging level returned by logging::GetMinLogLevel(). This way, testserver logs are printed on the console (in addition to being written to testserver.log) when tests are run in verbose mode. However, when tests are run in non-verbose mode, testserver logs are only written to the log file, but not to the console.

BUG=71241
TEST=sync_integration_tests

Review URL: http://codereview.chromium.org/6404003

git-svn-id: http://src.chromium.org/svn/trunk/src/net/tools/testserver@73330 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/testserver.py b/testserver.py
index eb2a02e..871e540 100755
--- a/testserver.py
+++ b/testserver.py
@@ -1389,8 +1389,11 @@
 
 def main(options, args):
   logfile = open('testserver.log', 'w')
-  sys.stdout = FileMultiplexer(sys.stdout, logfile)
   sys.stderr = FileMultiplexer(sys.stderr, logfile)
+  if options.log_to_console:
+    sys.stdout = FileMultiplexer(sys.stdout, logfile)
+  else:
+    sys.stdout = logfile
 
   port = options.port
 
@@ -1489,6 +1492,11 @@
                            const=SERVER_SYNC, default=SERVER_HTTP,
                            dest='server_type',
                            help='start up a sync server.')
+  option_parser.add_option('', '--log-to-console', action='store_const',
+                           const=True, default=False,
+                           dest='log_to_console',
+                           help='Enables or disables sys.stdout logging to '
+                           'the console.')
   option_parser.add_option('', '--port', default='0', type='int',
                            help='Port used by the server. If unspecified, the '
                            'server will listen on an ephemeral port.')