天天看点

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

首先看一下效果图:

python 技术篇-使用logging日志模块自定义时间格式
下面是我定义的日志格式:

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() 函数。

喜欢的点个赞❤吧!