Separate test logs of different xdist worker (#11495)

Signed-off-by: ThreadDao <yufen.zong@zilliz.com>
pull/11520/head
ThreadDao 2021-11-09 19:14:26 +08:00 committed by GitHub
parent 0a279df98a
commit 3a8acb03ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -6,6 +6,7 @@ class LogConfig:
self.log_debug = ""
self.log_err = ""
self.log_info = ""
self.log_worker = ""
self.get_default_config()
@staticmethod
@ -32,6 +33,9 @@ class LogConfig:
self.log_debug = "%s/ci_test_log.debug" % log_dir
self.log_info = "%s/ci_test_log.log" % log_dir
self.log_err = "%s/ci_test_log.err" % log_dir
work_log = os.environ.get('PYTEST_XDIST_WORKER')
if work_log is not None:
self.log_worker = f'{log_dir}/{work_log}.log'
self.create_path(log_dir)

View File

@ -157,7 +157,8 @@ def initialize_env(request):
assert ip_check(host) and number_check(port)
""" modify log files """
cf.modify_file(file_path_list=[log_config.log_debug, log_config.log_info, log_config.log_err], is_modify=clean_log)
cf.modify_file(file_path_list=[log_config.log_debug, log_config.log_info, log_config.log_err, log_config.log_worker],
is_modify=clean_log)
log.info("#" * 80)
log.info("[initialize_milvus] Log cleaned up, start testing...")

View File

@ -5,11 +5,12 @@ from config.log_config import log_config
class TestLog:
def __init__(self, logger, log_debug, log_file, log_err):
def __init__(self, logger, log_debug, log_file, log_err, log_worker):
self.logger = logger
self.log_debug = log_debug
self.log_file = log_file
self.log_err = log_err
self.log_worker = log_worker
self.log = logging.getLogger(self.logger)
self.log.setLevel(logging.DEBUG)
@ -32,6 +33,11 @@ class TestLog:
eh.setFormatter(formatter)
self.log.addHandler(eh)
wh = logging.FileHandler(self.log_worker)
wh.setLevel(logging.DEBUG)
wh.setFormatter(formatter)
self.log.addHandler(wh)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
@ -45,4 +51,5 @@ class TestLog:
log_debug = log_config.log_debug
log_info = log_config.log_info
log_err = log_config.log_err
test_log = TestLog('ci_test', log_debug, log_info, log_err).log
log_worker = log_config.log_worker
test_log = TestLog('ci_test', log_debug, log_info, log_err, log_worker).log