I have a program that give a logging information in log file but now I have created a folder named as LogFolder
I'm keeping my log file at the same folder but I want to create every time a new file when its increases the maxBytes size with different name
My log file is written in json format if you know normal format also for same query then you can help me with that.
My logging.json
file is:
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"json": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
"()": "pythonjsonlogger.jsonlogger.JsonFormatter"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "json",
"stream": "ext://sys.stdout"
},
"file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "json",
"filename": "..\\LogFloder\\Data.log",
"mode": "a",
"maxBytes": 25600,
"encoding": "utf8"
}
},
"root": {
"level": "DEBUG",
"handlers": ["console", "file_handler"]
}
}
This is how I call it in my python file main.py
:
import logging.config
import json
fp = open('logging.json')
logging.config.dictConfig(json.load(fp))
logging.getLogger("requests").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
logger.removeHandler(default_handler)
fp.close()
Here all the things are working very fine. I just want to make new log file with different name in LogFolder
when its exceeds the maxbytes size ...please help me how to do it.
Thanks in advance..