I have a python flask app running on EC2.
To enable UI interface to be functional, I run this on ec2 after logging in as the correct user:
uwsgi --socket 0.0.0.0:8000 --protocol=http -w wsgi:application -z 120 --http-timeout 120 --enable-threads -H /home/test/env --daemonize /home/test/test.log
and the UI becomes operational. When i click the download button certain computations take place before the csv becomes ready to download. I don’t have a uwsgi.ini file or any kind of nginx.
After a point the test.log becomes a very large file;
How do I write log files so that each days log gets written to a separate file?
or what is the best way to prevent one large log file from getting generated and instead have something that is more manageable?
2
Answers
You could implement log rotation using Python logging handlers:
https://docs.python.org/3/library/logging.handlers.html#rotatingfilehandler
This would rollover the logs when the
maxBytes
size has been reached. The primary log file will remaintest.log
but the filled log will be renamed totest.log.1
,test.log.2
and so on.Uses the
TimedRotatingFileHandler
class.The
TimedRotatingFileHandler
object will create a log file for each day, but you will have to handle it within the server application code