1

I'm trying to split my HAProxy (v1.6.12) logs so that one file only contains the HTTP request logs, while the other contains only start/stop/etc logs. I have this in my config:

 global log 127.0.0.1 local2 notice log 127.0.0.1 local3 info info 

As you can see, I'm trying to limit local3 to only info logs, while local2 gets logs at level notice and above.

local2 correctly only receives logs at the notice level and above. However, local3 is still getting all of start/stop logs, which are logged at the notice level. So this tells me that I'm maybe using the min log level stuff wrong? Or is there a bug?

Thanks!

1 Answer 1

0

Took me a while to figure it out myself, but looks like the answer is by modifying the log format and rsyslog settings, because haproxy doesn't provide any "access logs" level.

Here is an example of what I did:

global log 127.0.0.1:514 len 65535 local0 info chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners stats timeout 30s user haproxy group haproxy daemon defaults log global mode http frontend http-in bind *:443 ssl crt /usr/local/ssl/haproxy.pem default_backend response-ok option http-buffer-request declare capture request len 2000000000 http-request capture req.body id 0 log-format "[http-request]: %ci,%[capture.req.hdr(0)]" backend response-ok errorfile 503 /etc/haproxy/errors/200.http 

Now the next step is to change rsyslog to write all logs that starts with "[http-request]" to a different file, so I edited /etc/rsyslog.d/49-haproxy.conf like that:

# Collect log with UDP $ModLoad imudp $UDPServerAddress 127.0.0.1 $UDPServerRun 514 # We add :2: to remove leading whitespace $template access_logs_form, "%msg:2:$:%\n" # Send HAProxy access logs :msg, contains, "[http-request]:" { /var/log/haproxy/haproxy-traffic.log;access_logs_form stop } # Send HAProxy messages to a dedicated logfile :programname, startswith, "haproxy" { /var/log/haproxy/haproxy.log stop } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.