filter program logs in freebsd syslog
I had the need to filter logs from different programs into different places - in this case the postgres and nginx logs. The man page of syslog.conf
describes it pretty good, but misses some examples to make it more clear. So here is how I configured it, to make it easier.
First, I edited the syslog.conf
# filter everything apart from postgres and nginx
!-postgres,nginx
*.err;kern.warning;auth.notice;mail.crit /dev/console
# and all the other stuff
# filter only postgres
!postgres
*.* /var/log/postgresql.log
# filter only nginx
!nginx
*.* /var/log/nginx.log
The next step is to setup the log rotate. This happens in /etc/newsyslog.conf
. The man page is very helpful, so if you want to adjust something, take a peek into it.
# postgresql
/var/log/postgresql.log 640 5 100 * JC
# nginx
/var/log/nginx.log 640 5 100 * JC
And that is all. If you want to add more program filtes, you have to define them in the syslog.conf
as notfilter and filter and add the rotate to newsyslog.conf
.