python 技术篇-日志模块自定义时间格式

时间:2022-07-25
本文章向大家介绍python 技术篇-日志模块自定义时间格式,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

首先看一下效果图:

下面是我定义的日志格式:

import logging

logging.basicConfig(filename = path + 'log_' + today_date + '.txt', level = logging.DEBUG, filemode = 'a', format = '【%(asctime)s】 【%(levelname)s】 >>>  %(message)s', datefmt = '%Y-%m-%d %H:%M')

其中datefmt = '%Y-%m-%d %H:%M'参数用来定义时间格式。 兼容 strftime() 日期/时间格式字符串,可以参照 strftime() 函数。