Logging haproxy via rsyslog…

Simple haproxy logging setup:

# /etc/rsyslog.d/haproxy.conf
$ModLoad imudp
$UDPServerRun 514
$template Haproxy,"%msg%\n"
local2.=info -/var/log/haproxy.log;Haproxy
local2.notice -/var/log/haproxy-status.log;Haproxy
### keep logs in localhost ##
local2.* ~

Don’t forget to rotate the logs:

# /etc/logrotate.d/haproxy
/var/log/haproxy.log /var/log/haproxy-status.log {
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

Restart rsyslog and haproxy, or reboot.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *