Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active February 9, 2018 12:53
Show Gist options
  • Save drmalex07/ef5ae7c5c110d0fe2f8e to your computer and use it in GitHub Desktop.
Save drmalex07/ef5ae7c5c110d0fe2f8e to your computer and use it in GitHub Desktop.
Enable syslog local logging for an application running under uWSGI. #wsgi #uwsgi #logging #syslog #rsyslog

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment