The following recipe is tested on a debian 7.x system.
Start the uWSGI server to serve the application. The following example assumes a paste-deployed helloworld
app. We choose to log under local0
syslog facility with a name of helloworld
uwsgi --ini-paste-logged $(pwd)/development.ini --pidfile /tmp/helloworld.pid --logger syslog:helloworld,local0
or, as a daemon
uwsgi --ini-paste-logged $(pwd)/development.ini --pidfile /tmp/helloworld.pid --daemonize $(pwd)/development.ini --logger syslog:helloworld,local0
Configure rsyslog
to log messages for facility local0
to a separate logfile. Edit /etc/rsyslog.conf
(as root) and add the line:
local0.* /var/log/local0.log
Restart rsyslog
daemon for changes to take effect.
sudo invoke-rc.d rsyslog restart
Now, configure rotation for our new logfile. Edit /etc/logrotate.d/rsyslog
(as root) and add a respective block (see detailed logrotate options with man logrotate
):
/var/log/local0.log
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
We dont need to restart anything, as usually logrotate is invoked as a daily cron job (as /etc/cron.daily/logrotate
or something similar). However, if we want to test our configuration we can manually invoke it as:
sudo logrotate /etc/logrotate.conf