# coding=utf-8
import os
import sys
from loguru import logger
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
log_file_path = os.path.join(BASE_DIR, 'Log/my.log')
err_log_file_path = os.path.join(BASE_DIR, 'Log/err.log')
#设置日志格式,过滤器,日志级别
logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO")
# logger.add(s)
#按照日志文件大小,生成日志文件
logger.add(log_file_path, rotation="500 MB", encoding='utf-8') # Automatically rotate too big file
logger.add(err_log_file_path, rotation="500 MB", encoding='utf-8',
level='ERROR') # Automatically rotate too big file
logger.debug("That's it, beautiful and simple logging!")
logger.debug("中文日志可以不")
logger.error("严重错误")
D:UsersheguanghuaAppDataLocalProgramsPythonPython35python.exe E:/untitled/comm/test_case.py
2020-07-24 14:44:46.514 | DEBUG | __main__:<module>:16 - That's it, beautiful and simple logging!
2020-07-24 14:44:46.514 | DEBUG | __main__:<module>:17 - 中文日志可以不
2020-07-24 14:44:46.514 | ERROR | __main__:<module>:18 - 严重错误
Process finished with exit code 0
详见此链接:https://www.cnblogs.com/Super-Treasure/p/13356554.html