How do you add datetime to a logfile name?

后端 未结 7 654
孤街浪徒
孤街浪徒 2020-12-29 19:42

When I create my logfile, I want the name to contain the datetime.

In Python you can get the current datetime as:

>>> from datetime import da         


        
7条回答
  •  感动是毒
    2020-12-29 19:58

    from time import strftime
    
    fh = logging.FileHandler(strftime("mylogfile_%H_%M_%m_%d_%Y.log"))
    

提交回复
热议问题