Skip to main content
 首页 » 编程设计

python之更高精度的日志记录模块时间格式

2025年02月15日7虾米哥

<分区>

我正在使用 Python 的日志记录模块,我需要获取有关不同函数调用的开始和结束时间的信息。为此,我目前正在使用

formatter = logging.Formatter('%(message)s %(asctime)s.%(msecs)03d %(levelname)s', 
                              datefmt='%H:%M:%S') 

由于特定函数的调用不会持续超过几毫秒,我希望获得更好的精度并有更多的小数位数。我该怎么做?

我很好的解决方案:Python logging: use milliseconds in time format