I am using this configuration for my logging system.
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"format": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "format",
"stream": "ext://sys.stdout",
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"filename": "data/logs/main.log",
"mode": "a",
"formatter": "format",
"maxBytes": 1024 * 1024,
"backupCount": 100,
},
},
"root": {"handlers": ["console", "file"], "level": "DEBUG"},
}
)
this configuration makes 11 log files for my project with these names:
main.log
main.log.1
main.log.2
…
main.log.99
main.log.100
I want these names to be something like these:
main.log
main-00.log
main-01.log
…
main-98.log
main-99.log
How can I do this customization on the name of log files?
Another problem is that main-36.log
may have the newest logs and so main-37.log
has the oldest logs.
I want when the size of main.log reaches the maxBytes all of the log files to shift one (
main-01.log
copy tomain-00.log
main-02.log
copy tomain-01.log
…
main-98.log
copy tomain-97.log
main-99.log
copy tomain-98.log
) and after that main.log copy on last file (main-99.log
).
in this order, main-99.log
always has the newest logs and main-00.log
always has the oldest logs
How can I do these?