2021-07-02 03:40:16 +00:00
|
|
|
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
|
|
|
|
"""
|
2021-10-25 11:27:21 +00:00
|
|
|
print(global_params.log_file_path)
|
2021-07-02 03:40:16 +00:00
|
|
|
try:
|
|
|
|
with open(config_path, 'rt') as f:
|
|
|
|
log_config = yaml.safe_load(f.read())
|
2021-10-25 11:27:21 +00:00
|
|
|
log_config["handlers"]["info_file_handler"].update({"filename": global_params.log_file_path})
|
2021-07-02 03:40:16 +00:00
|
|
|
logging.config.dictConfig(log_config)
|
|
|
|
except Exception:
|
2021-10-20 11:15:23 +00:00
|
|
|
raise logging.error('Failed to open file', exc_info=True)
|
2021-10-25 11:27:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GlobalParams:
|
|
|
|
log_file_path = FILE_NAME
|
2021-10-27 11:04:30 +00:00
|
|
|
config_path = ''
|
2021-10-26 06:34:54 +00:00
|
|
|
metric = None
|
2021-10-25 11:27:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
global_params = GlobalParams()
|