You don’t want to do this from within your Django process. Your code does not control the process in which its being run. This is why things like Celery are started external to the main process.
This is no guarantee.
See the response and the linked messages at I'm new to WebDev, explain to me why or why it wouldn't be OK for all users to access a global Lark() parser object? - #8 by KenWhitesell to get an idea of some of the reasons why this is bad. (What’s going to happen when your process is restarted? What’s going to happen when multiple instances of the process are started?)
This is not something you need to write.
The Python RotatingFileHandler will do this for you. If you need to perform some specific processing when the files are rotated, you can implement your own rotate handler.