import_data_log.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2024/5/16
  3. # @Author : 魏志亮
  4. import datetime
  5. import logging
  6. import sys
  7. from os import *
  8. from utils.common_util import get_project_conf_path_file
  9. from utils.conf.read_conf import read_conf, yaml_conf
  10. logger = logging.getLogger("ImportData_Python")
  11. logger.setLevel(logging.INFO)
  12. stout_handle = logging.StreamHandler(sys.stdout)
  13. stout_handle.setFormatter(
  14. logging.Formatter("%(asctime)s: %(message)s"))
  15. stout_handle.setLevel(logging.INFO)
  16. logger.addHandler(stout_handle)
  17. conf_path = get_project_conf_path_file('dev')
  18. config = yaml_conf(environ.get('IMPORT_CONF', conf_path))
  19. log_path_dir = read_conf(config, 'log_path_dir', "/data/logs")
  20. log_path = log_path_dir + sep + r'ImportData_Python_' + (environ['env'] if 'env' in environ else 'dev')
  21. file_path = path.join(log_path)
  22. if not path.exists(file_path):
  23. makedirs(file_path, exist_ok=True)
  24. file_name = file_path + sep + str(datetime.date.today()) + '.log'
  25. file_handler = logging.FileHandler(file_name, encoding='utf-8')
  26. file_handler.setFormatter(
  27. logging.Formatter("%(asctime)s: %(message)s"))
  28. file_handler.setLevel(logging.INFO)
  29. logger.addHandler(file_handler)
  30. def log_print(*args):
  31. logger.info(" ".join([str(a) for a in args]))