您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

29 行
966B

  1. import logging
  2. import sys
  3. def _reset_logger(log):
  4. for handler in log.handlers:
  5. handler.close()
  6. log.removeHandler(handler)
  7. del handler
  8. log.handlers.clear()
  9. log.propagate = False
  10. console_handle = logging.StreamHandler(sys.stdout)
  11. console_handle.setFormatter(logging.Formatter('[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d] - %(message)s',
  12. datefmt='%Y-%m-%d %H:%M:%S'))
  13. file_handle = logging.FileHandler('run.log', encoding='utf-8')
  14. file_handle.setFormatter(logging.Formatter('[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d] - %(message)s',
  15. datefmt='%Y-%m-%d %H:%M:%S'))
  16. log.addHandler(file_handle)
  17. log.addHandler(console_handle)
  18. def _get_logger():
  19. log = logging.getLogger('log')
  20. _reset_logger(log)
  21. log.setLevel(logging.INFO)
  22. return log
  23. # 日志句柄
  24. logger = _get_logger()