I am setting up python logger using config. I want log file to contain date (and possibly time). I also want for that date, each log file to be of only particular size and to keep only 3 such old log files.
For example, I will like to get log files of following form:
mylog-2018-09-11.log
mylog-2018-09-11.log.1
mylog-2018-09-11.log.2
mylog-2018-09-11.log.3
I tried RotatingFileHandler using config of following form as explained here:
config = {
#...
'handlers': {
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'mplog.log',
'mode': 'w',
'formatter': 'detailed',
'maxBytes': 10000,
'backupCount': 3
},
},
#...
}
logging.config.dictConfig(config)
and it produces log files as follows:
mylog.log
mylog.log.1
mylog.log.2
mylog.log.3
But I am unable to understand, how can I get date in the log file names. Is it possible to do it with configs and with some handler say RotatingFileHandler
or TimeRotatingFileHandler
? Or say can I somehow set the log file name to contain date after dictConfig()
call?