# -*- coding: utf-8 -*- # @Time : 2024/5/16 # @Author : 魏志亮 import datetime import logging import sys from os import * from utils.common_util import get_project_conf_path_file from utils.conf.read_conf import read_conf, yaml_conf logger = logging.getLogger("ImportData_Python") logger.setLevel(logging.INFO) stout_handle = logging.StreamHandler(sys.stdout) stout_handle.setFormatter( logging.Formatter("%(asctime)s: %(message)s")) stout_handle.setLevel(logging.INFO) logger.addHandler(stout_handle) conf_path = get_project_conf_path_file('dev') config = yaml_conf(environ.get('IMPORT_CONF', conf_path)) log_path_dir = read_conf(config, 'log_path_dir', "/data/logs") log_path = log_path_dir + sep + r'ImportData_Python_' + (environ['env'] if 'env' in environ else 'dev') file_path = path.join(log_path) if not path.exists(file_path): makedirs(file_path, exist_ok=True) file_name = file_path + sep + str(datetime.date.today()) + '.log' file_handler = logging.FileHandler(file_name, encoding='utf-8') file_handler.setFormatter( logging.Formatter("%(asctime)s: %(message)s")) file_handler.setLevel(logging.INFO) logger.addHandler(file_handler) def log_print(*args): logger.info(" ".join([str(a) for a in args]))