默认情况下logging.Formatter('%(asctime)s')
使用以下格式打印:
2011-06-09 10:54:40,638
其中 638 是毫秒。我需要将逗号更改为点:
2011-06-09 10:54:40.638
要格式化时间,我可以使用:
logging.Formatter(fmt='%(asctime)s',datestr=date_format_str)
但是,那文档 http://docs.python.org/library/time.html#time.strftime没有指定如何格式化毫秒。我发现了这个问题 https://stackoverflow.com/questions/698223/how-can-i-parse-a-time-string-containing-milliseconds-in-it-with-python其中讨论了微秒,但是a)我更喜欢毫秒,b)以下内容在Python 2.6(我正在开发)上不起作用,因为%f
:
logging.Formatter(fmt='%(asctime)s',datefmt='%Y-%m-%d,%H:%M:%S.%f')
这也应该有效:
logging.Formatter(
fmt='%(asctime)s.%(msecs)03d',
datefmt='%Y-%m-%d,%H:%M:%S'
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)