简体   繁体   中英

How do I change the filename python's logging library outputs to?

I am using a TimedRotatingFileHandler for my Python project for logging. However, when it's time for a rollover, it changes my base file name from baseName.log to baseName.log.(TimeStamp) , what can I do so it instead looks like baseName.(TimeStamp).log .

That way who ever is using it doesn't have to configure what program to use each time it try to open it.

Unfortunately, this feature is not present in logging . However, you can very easily use the message formatting of this library to output a time stamp of each message logged in your file. Afterwards, a very simple python script could allow you to break down the files into two for all timestamps greater to whatever you want.

FORMAT = '%(asctime)- %(message)s'
logging.basicConfig(format=FORMAT)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM