I set up haproxy logging via rsyslogd using the tips from this article, and everything seems to be working fine. The log files get the log messages.
However, every log message from haproxy also shows up at /var/log/syslog
. This means that once the server goes live, the syslog will be quite useless, as it will be run over with haproxy log messages.
I would like to filter out those messages from /var/log/syslog
. After going over the rsyslogd documentation, I tried to change the file /etc/rsyslog.d/50-default.conf
thus:
*.*;auth,authpriv.none;haproxy.none -/var/log/syslog
I simply added the ;haproxy.none
part. After restarting rsyslogd it stopped working completely until I reverted my changes.
What am I doing wrong?
You could also do the following which will make it so they don't go in any other logs:
The
& ~
means not to put what matched in the above line anywhere else for the rest of the rules.The use of
& ~
was deprecated in v7 of rsyslogd, and you're encouraged to use& stop
instead. You can read more about it in this section of the v7compatibility page.So for HAProxy something like this instead:
As to how it works, the
& stop
tells rsyslogd to discard any additional messages that matched the previously matched rules up to this point. To guarantee that this rule is picked up early on, you can change the name of the file from/etc/rsyslog.d/haproxy.conf
to/etc/rsyslog.d/00-haproxy.conf
.Ok, I figured it out. This is what my
/etc/rsyslog.d/20-haproxy.conf
looks like:I changed the line in
50-default.conf
to:And now it seems to be doing what I want.
There is a better solution for haproxy logging.
/dev/log
According to official manual rsyslog needs to be configured to listen to the network socket:
But you can use only rsyslog sockets for that:
rsyslog.d/haproxy.conf:
haproxy.cfg:
I prefer not to mess with the ordering of the file so instead i add a local0.none to the . line entry. Config looks like:
(Tested on CentOS 7)
Hope that helps!