Python logging: use milliseconds in time format

后端 未结 10 1861
不知归路
不知归路 2020-12-02 05:36

By default logging.Formatter(\'%(asctime)s\') prints with the following format:

2011-06-09 10:54:40,638

where 638 is the milli

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 05:50

    As of now the following works perfectly with python 3 .

             logging.basicConfig(level=logging.DEBUG,
                         format='%(asctime)s %(levelname)-8s %(message)s',
                         datefmt='%Y/%m/%d %H:%M:%S.%03d',
                         filename=self.log_filepath,
                         filemode='w')
    

    gives the following output

    2020/01/11 18:51:19.011 INFO

提交回复
热议问题