How to create one uwsgi log file per day?

Markus Johansson picture Markus Johansson · Feb 5, 2015 · Viewed 12.7k times · Source

I use uwsgi with the parameter --daemonize /logs/uwsgi.log

This file is however becoming large and I would like to split it into smaller pieces. One per day would be preferable. I have done that for nginx where it was easy to specify the log file name using date variables. Is it possible to do the same for uwsgi?

Something like:

[uwsgi]
daemonize=/logs/uwsgi-$year-$month-$day.log

Or is there another way to get the same result, without too much involvement of other processes?

Answer

roberto picture roberto · Feb 5, 2015

uWSGI by itself can only "split by size", with the --log-maxsize option.

Time-based approaches are using classic logrotate or apache rotatelogs (http://httpd.apache.org/docs/2.2/programs/rotatelogs.html) that you can combine with uWSGI logpipe plugin.

Finally you can have an nginx like behaviour triggering a reload at midnight of the uWSGI instance (you can even use the embedded cron facility):

[uwsgi]
daemonize = /logs/uwsgi-@(exec://date +%%Y-%%m-%%d).log
log-reopen = true