简体   繁体   中英

Rotating logs using RotatingFileHandler by date in Python

I am looking for a method which will allow me to rotate the logs at midnight instead of rotating them using the maxBytes parameter.

So far, the logs are rotated when a file reaches 10MB.

LOG_PATH = os.path.join(APPLICATION_PATH, "log\\My_log.log")

my_handler = RotatingFileHandler(LOG_PATH, mode='a', maxBytes=10000000, backupCount=20)
logger.addHandler(my_handler) 

Is there a way of passing a date parameter to RotatingFileHandler() so that instead of rotating after the file reaches 10MB it will rotate the file at midnight ?

使用TimedRotatingFileHandler

my_handler = TimedRotatingFileHandler(LOG_PATH, when='midnight', backupCount=20)

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