]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Attach FileHandlers to the RootLogger object
authorZack Cerza <zack.cerza@inktank.com>
Wed, 13 Aug 2014 19:10:15 +0000 (13:10 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Wed, 13 Aug 2014 19:10:15 +0000 (13:10 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/__init__.py
teuthology/coverage.py
teuthology/results.py
teuthology/run.py
teuthology/worker.py

index 2ae5aac77076524bba34b137155eb4aa37c5de82..6d19e6de9bf02d27ad0c6faccb714007307ad04a 100644 (file)
@@ -18,10 +18,18 @@ logging.basicConfig(
 log = logging.getLogger(__name__)
 
 
-def setup_log_file(logger, log_path):
-    log_formatter = logging.Formatter(
+def setup_log_file(log_path):
+    root_logger = logging.getLogger()
+    handlers = root_logger.handlers
+    for handler in handlers:
+        if isinstance(handler, logging.FileHandler) and \
+                handler.stream.name == log_path:
+            log.debug("Already logging to %s; not adding new handler",
+                      log_path)
+            return
+    formatter = logging.Formatter(
         fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s',
         datefmt='%Y-%m-%dT%H:%M:%S')
-    log_handler = logging.FileHandler(filename=log_path)
-    log_handler.setFormatter(log_formatter)
-    logger.addHandler(log_handler)
+    handler = logging.FileHandler(filename=log_path)
+    handler.setFormatter(formatter)
+    root_logger.addHandler(handler)
index f5938d429b3f13872aef9a232fe99ba9d8f4718c..f877ee0b043474598ff2b8714bdc05afba05e3e0 100644 (file)
@@ -98,7 +98,7 @@ def main(args):
     read_config(args)
 
     log_path = os.path.join(args.test_dir, 'coverage.log')
-    teuthology.setup_log_file(log, log_path)
+    teuthology.setup_log_file(log_path)
 
     try:
         analyze(args)
index 7a647945ef1b2bdbed82a922bb0609210fe7d3a5..586a6c5e5cded11aaf20ff4f4afad276a9f343f7 100644 (file)
@@ -24,7 +24,7 @@ def main(args):
     misc.read_config(args)
 
     log_path = os.path.join(args.archive_dir, 'results.log')
-    teuthology.setup_log_file(log, log_path)
+    teuthology.setup_log_file(log_path)
 
     try:
         results(args)
index 373bffe267dead4f56672f0d857febfe48c8417c..abc04228f561df09a5e0bb92170a8981df7d21e4 100644 (file)
@@ -23,9 +23,7 @@ def set_up_logging(ctx):
     if ctx.archive is not None:
         os.mkdir(ctx.archive)
 
-        teuthology.setup_log_file(
-            logging.getLogger(),
-            os.path.join(ctx.archive, 'teuthology.log'))
+        teuthology.setup_log_file(os.path.join(ctx.archive, 'teuthology.log'))
 
     install_except_hook()
 
index 77aad4a7af8cb6cd87af80d427283853eba0e899..1d7970b964a5dd2627d4426a8c2fc338f60e6b99 100644 (file)
@@ -61,7 +61,7 @@ def main(ctx):
 
     log_file_path = os.path.join(ctx.log_dir, 'worker.{tube}.{pid}'.format(
         pid=os.getpid(), tube=ctx.tube,))
-    setup_log_file(log, log_file_path)
+    setup_log_file(log_file_path)
 
     install_except_hook()