5

I have a current generation Linux system I'd like to use with haproxy. Journald will happily log stdout from .service, and mark the log as coming from that service, but haproxy doesn't seem to be able to log to stdout.

What's the simplest and cleanest way to get haproxy to log to systemd/journald?

Edit: current configuration is the default:

global
    log         127.0.0.1 local2

But there's no local2 facility since there's no syslog on the local box.

4
  • What distribution and version?
    – GregL
    Oct 9, 2015 at 17:51
  • @GregL CentOS 7 and haproxy-1.5.4-4.el7_1.1.x86_64 Oct 9, 2015 at 18:15
  • And how do you have HAProxy currently configured to log?
    – GregL
    Oct 9, 2015 at 18:17
  • @GregL Added current log settings above Oct 11, 2015 at 19:09

2 Answers 2

12

Systemd has a Unix domain socket you can log to:

global
        log /dev/log local0 info

Then systemctl restart haproxy to make the changes take effect.

6
  • 1
    Dang it, I meant to post an answer with just that, but kept forgetting. Glad you found a way.
    – GregL
    Oct 14, 2015 at 17:21
  • 1
    @mikemaccana does not create log files for me, but outputs messages to stdout like this [ALERT] 079/115253 (7) : sendto logger #1 failed: Connection refused (errno=111)
    – FelikZ
    Mar 20, 2016 at 11:54
  • 1
    @FelikZ Best to ask as a separate question. Sounds like the systemd socket file doesn't exist. Mar 23, 2016 at 13:40
  • @mikemaccana it is actually the answer. I am running that in docker and by default no logging service running
    – FelikZ
    Mar 23, 2016 at 13:44
  • 1
    This will not work if you're using a chrooted environment.
    – ibizaman
    Apr 19, 2019 at 22:28
1

This answer goes for those struggling. haproxy_global.cfg =>

global
    log                 127.0.0.1:514 local0

defaults
    mode                    http
    log                     global
    log-format              "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"

/etc/rsyslog.d/haproxy.conf =>

    # Collect log with UDP
    $ModLoad imudp
    $UDPServerAddress 127.0.0.1
    $UDPServerRun 514

    $AddUnixListenSocket /var/lib/haproxy/dev/log
    # Send HAProxy messages to a dedicated logfile
    :programname, startswith, "haproxy" {
      /var/log/haproxy/haproxy.log
      stop
    }

/etc/logrotate.d/haproxy =>

  /var/log/haproxy/haproxy.log {
      missingok
      notifempty
      sharedscripts
      rotate 14
      daily
      compress
      postrotate
          reload rsyslog >/dev/null 2>&1 || true
      endscript
  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .