loguru关闭console输出

# 关闭sys.stderr,即关闭console输出
logger.remove(handler_id=None)
# 生成日志文件,utf-8编码,每天0点切割,zip压缩,保留30天
log_path = join(dirname(dirname(abspath(__file__))), 'log', 'sms_send.log')
logger.add(log_path+'_{time}', level="INFO", rotation='00:00',retention='30 days', compression='zip', encoding='utf-8')
logger.debug("日志保存路径:"+log_path)

参考:

https://loguru.readthedocs.io/en/stable/api/logger.html

remove(handler_id=None)[source]
Remove a previously added handler and stop sending logs to its sink.

Parameters:handler_id (int or None) – The id of the sink to remove, as it was returned by the add() method. If None, all handlers are removed. The pre-configured handler is guaranteed to have the index 0.
Raises:ValueError – If handler_id is not None but there is no active handler with such id.

You may also like...

发表评论