Python log library Loguru tutorial (the most user-friendly Python log module)

Python log library Loguru tutorial (the most user-friendly Python log module)

Reset loguru output: only output to text, do not output to console
The logger has console output by default, that is, sys.stderr. If you want to only output to text but not to console, just close sys.stderr.
Just clean up the previous handler settings directly, and then reset one further, such as outputting to the feature text:

from loguru import logger
# Remove a previously added handler and stop sending logs to its sink.
logger.remove(handler_id=None)  # 清除之前的设置
# 设置生成日志文件,utf-8编码,每天0点切割,zip压缩,保留3天,异步写入
logger.add(sink='test.log', level=”INFO”, rotation=00:00, retention=3 days’, compression=zip, encoding=’utf-8, enqueue=True)  

Guess you like

Origin blog.csdn.net/kunwen123/article/details/131912389