milvus/tests/benchmark/milvus_benchmark/logs/log.py
wt 924614ca69
[skip ci] Add config_path of benchmark (#10767)
Signed-off-by: wangting0128 <ting.wang@zilliz.com>
2021-10-27 19:04:30 +08:00

33 lines
896 B
Python

import logging.config
from datetime import datetime
import os
import yaml
import config
cur_path = os.path.abspath(os.path.dirname(__file__))
LOG_CONFIG_PATH = cur_path + "/logging.yaml"
FILE_NAME = config.LOG_PATH + 'benchmark-{:%Y-%m-%d}.log'.format(datetime.now())
def setup_logging(config_path=LOG_CONFIG_PATH, default_level=logging.INFO):
"""
Setup logging configuration
"""
print(global_params.log_file_path)
try:
with open(config_path, 'rt') as f:
log_config = yaml.safe_load(f.read())
log_config["handlers"]["info_file_handler"].update({"filename": global_params.log_file_path})
logging.config.dictConfig(log_config)
except Exception:
raise logging.error('Failed to open file', exc_info=True)
class GlobalParams:
log_file_path = FILE_NAME
config_path = ''
metric = None
global_params = GlobalParams()