logger.py 613 B

12345678910111213141516171819
  1. import os
  2. from loguru import logger
  3. from pathlib import Path
  4. from datetime import datetime
  5. def setup_log(config):
  6. """
  7. Setup logging
  8. :param config: config file
  9. :return:
  10. """
  11. log_path = os.path.join(Path(__file__).parent.parent, "log")
  12. if not Path(log_path).exists():
  13. Path(log_path).mkdir(parents=True, exist_ok=True)
  14. log_level = config.get("LOG_LEVEL")
  15. log_name = f'log_{datetime.now().strftime("%Y-%m-%d")}.log'
  16. log_file_path = os.path.join(log_path, log_name)
  17. logger.add(str(log_file_path), rotation='00:00', encoding='utf-8', level=log_level, enqueue=True)