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)
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)
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)
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()
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()