]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Consolidate log file setup into shared function
authorZack Cerza <zack@cerza.org>
Wed, 7 May 2014 16:02:52 +0000 (11:02 -0500)
committerZack Cerza <zack@cerza.org>
Sat, 10 May 2014 14:10:21 +0000 (09:10 -0500)
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 bd88d3cc7739f98b1782b11a10e877656e4b3f96..29b85ea8dfaced2f41c421cd2cab3f26d7b4d1fa 100644 (file)
@@ -4,5 +4,17 @@ from .orchestra import monkey
 monkey.patch_all()
 
 import logging
-logging.basicConfig(level=logging.INFO, format='%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s')
+
+logging.basicConfig(
+    level=logging.INFO,
+    format='%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s')
 log = logging.getLogger(__name__)
+
+
+def setup_log_file(logger, log_path):
+    log_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)
index 6fabb2f438585c7157d13cf4418b2c92e893aa5b..f5938d429b3f13872aef9a232fe99ba9d8f4718c 100644 (file)
@@ -97,15 +97,8 @@ def main(args):
 
     read_config(args)
 
-    handler = logging.FileHandler(
-        filename=os.path.join(args.test_dir, 'coverage.log'),
-    )
-    formatter = logging.Formatter(
-        fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(message)s',
-        datefmt='%Y-%m-%dT%H:%M:%S',
-    )
-    handler.setFormatter(formatter)
-    logging.getLogger().addHandler(handler)
+    log_path = os.path.join(args.test_dir, 'coverage.log')
+    teuthology.setup_log_file(log, log_path)
 
     try:
         analyze(args)
index eac44de1cd4bbbc33e1ba876294d27a6bedba2a1..4687a6fc3c87172c097392f7ef62a8baa90c9247 100644 (file)
@@ -23,15 +23,8 @@ def main(args):
 
     misc.read_config(args)
 
-    handler = logging.FileHandler(
-        filename=os.path.join(args.archive_dir, 'results.log'),
-    )
-    formatter = logging.Formatter(
-        fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(message)s',
-        datefmt='%Y-%m-%dT%H:%M:%S',
-    )
-    handler.setFormatter(formatter)
-    logging.getLogger().addHandler(handler)
+    log_path = os.path.join(args.archive_dir, 'results.log')
+    teuthology.setup_log_file(log, log_path)
 
     try:
         results(args)
index 94a938b51ef285e19b7e44493c93e2d6cd580e88..5d2dd9d5ac84bcbee3ce35005a658fdf0f01510b 100644 (file)
@@ -23,15 +23,9 @@ def set_up_logging(ctx):
     if ctx.archive is not None:
         os.mkdir(ctx.archive)
 
-        handler = logging.FileHandler(
-            filename=os.path.join(ctx.archive, 'teuthology.log'),
-        )
-        formatter = logging.Formatter(
-            fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s',
-            datefmt='%Y-%m-%dT%H:%M:%S',
-        )
-        handler.setFormatter(formatter)
-        logging.getLogger().addHandler(handler)
+        teuthology.setup_log_file(
+            logging.getLogger(),
+            os.path.join(ctx.archive, 'teuthology.log'))
 
     install_except_hook()
 
index 66147705787473887e3f19f55d5ec45eb9ac730a..f1ca4248dda5fb706199199c05da4252ce2c39fb 100644 (file)
@@ -10,6 +10,7 @@ import yaml
 
 from datetime import datetime
 
+from teuthology import setup_log_file
 from . import beanstalk
 from . import report
 from . import safepath
@@ -126,12 +127,7 @@ def main(ctx):
 
     log_file_path = os.path.join(ctx.log_dir, 'worker.{tube}.{pid}'.format(
         pid=os.getpid(), tube=ctx.tube,))
-    log_handler = logging.FileHandler(filename=log_file_path)
-    log_formatter = logging.Formatter(
-        fmt=u'%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s',
-        datefmt='%Y-%m-%dT%H:%M:%S')
-    log_handler.setFormatter(log_formatter)
-    log.addHandler(log_handler)
+    setup_log_file(log, log_file_path)
 
     if not os.path.isdir(ctx.archive_dir):
         sys.exit("{prog}: archive directory must exist: {path}".format(