uWSGI / Flask / Python logs stop after some time uWSGI / Flask / Python logs stop after some time flask flask

uWSGI / Flask / Python logs stop after some time


I'm not sure that this will help in your case, but you can try to use post forking in uWSGI.

The postfork decorator is just the ticket. You can declare multiple postfork tasks. Each decorated function will be executed in sequence after each fork().

@postforkdef init_logging():    app.logger.addHandler(handler)

Or you can specify lazy-apps=true in your uwsgi.ini.

For details: http://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html and http://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html


I can tell you for sure is that restarting uwsgi should not stop logging. I have nginx-uwsgi-django server and I restart my uwsgi server all the time and my logs never stop. Here is what my ini file looks like: may be you can tweak your ini file as per this and see if it works.

1 #mysite_uwsgi.ini2 [uwsgi]3 4 # Django-related settings5 # the base directory (full path)6 chdir           = /home/user/bdapps_stage7 # Django's wsgi file8 module          = mysite.wsgi:application9 # the virtualenv (full path)10 home            = /home/user/.conda/envs/mysite_env/11 12 # process-related settings13 # master14 master          = true15 # maximum number of worker processes16 processes       = 317 # maximum number of threads to use18 # threads19 # the socket (use the full path to be safe20 socket          = /home/user/mysite/mysite.sock21 # ... with appropriate permissions - may be needed22 chmod-socket    = 66623 #set the sockets listen queue size24 #listen25 # clear environment on exit26 vacuum          = true

And here is how I restart my uwsgi

kill -SIGHUP [pid id of your uwsgi master]

Please note that the command you have provided for uwsgi using the ini file should only be used once to start the uwsgi server. When you want to restart, I suggest you note down the pid of the uwsgi master by using

 ps -ef | grep uwsgi 

and run the above kill command.


Venturing another possible cause for logging stopping after some time. uWSGI can be set to drop privileges (which is a good idea). However after this event logto2 [0] setting is used:

logto=/var/www/app.com/logs/uwsgi/app.com-0.loglogto2=/var/www/app.com/logs/uwsgi/app.com-normaluser-0.log

Hope it helps someone.

[0] https://uwsgi-docs.readthedocs.io/en/latest/Options.html#logto2