相关疑难解决方法(0)

Python日志记录:以时间格式使用毫秒

默认情况下logging.Formatter('%(asctime)s'),使用以下格式打印:

2011-06-09 10:54:40,638
Run Code Online (Sandbox Code Playgroud)

其中638是毫秒.我需要将逗号更改为点:

2011-06-09 10:54:40.638
Run Code Online (Sandbox Code Playgroud)

格式化我可以使用的时间:

logging.Formatter(fmt='%(asctime)s',datestr=date_format_str)
Run Code Online (Sandbox Code Playgroud)

但是文档没有指定如何格式化毫秒.我发现这个SO问题谈论微秒,但是a)我更喜欢毫秒和b)以下不适用于Python 2.6(我正在研究),因为%f:

logging.Formatter(fmt='%(asctime)s',datefmt='%Y-%m-%d,%H:%M:%S.%f')
Run Code Online (Sandbox Code Playgroud)

python time logging

141
推荐指数
7
解决办法
8万
查看次数

标签 统计

logging ×1

python ×1

time ×1