How can I get haproxy to log to systemd/journald?

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.


Solution 1:

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.

Solution 2:

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
  }