Haproxy configuration log and custom log
Log level:
The emerg 0 system is not available
Events in which alert 1 must act immediately
Key events in crit 2
Err 3 error event
Warning 4 warning event
Notice 5 ordinary but important events
Info 6 useful information
Debug 7 debugging Information
Configure logging:
By default, haproxy does not log.
Configure haproxy.cfg to log
Haproxy.cfg: enable haproxy logging
Log 127.0.0.1 local2
/ etc/rsyslog.conf: use rsyslog to receive logs:
Remove the comments from these two lines:
$ModLoad imudp
$UDPServerRun 514
Add this line:
Local2.* / var/log/haproxy.log
Restart rsyslog to see if port 514 of udp is enabled:
# / etc/init.d/rsyslog restart
# netstat-tunpl
Configure haproxy to log in more detail:
The default log is not readable, and we need to display more information, but it cannot be captured by default, so we can only customize what needs to be displayed.
Capture request header Host len 64
Capture request header User-Agent len 128
Capture request header X-Forwarded-For len 100
Capture request header Referer len 200
Capture response header Server len 40
Capture response header Server-ID len 40
Log-format% ci:%cp\% si:%sp\% B\% U\% ST\% r\% b\% f\% bi\% hrl\% hsl\
Just restart haproxy.
Capture request header reference official website: http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.8
The custom log format can be found on the official website: http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4