When HAProxy Enterprise runs as a Docker container, you have several ways to collect logs.

  • Forward logs to 'standard out', allowing you to capture them using a log aggregation tool

  • Forward logs to a remote Syslog server, which can run in a separate container

Log to standard out

This method publishes logs to stdout, allowing you to offload the collection of logs to an external tool, such as logspout.

  1. Place a log statement into the global section of your configuration file:

    • use stdout as the address

    • use format raw for a shortened log format compatible with a variety of tools

    • use local0 as the facility code

    global
      log stdout format raw local0
  2. Add a log global statement to a defaults section to enable the global logging rule in all subsequent listen, frontend, and backend sections:

    defaults
      log global
  3. View logs by querying the HAProxy Enterprise container using the docker logs command:

    $ sudo docker logs hapee

Log to a syslog container

This method allows you to forward logs to a container running a Syslog server, such as Rsyslog.

  1. Place a log statement into the global section of your configuration file:

    • use the IP address or name of your Syslog container, with an optional port number

    • use local0 as the facility code

    global
      log rsyslog:514 local0
  2. Add a log global statement to a defaults section to enable the global logging rule in all subsequent listen, frontend, and backend sections:

    defaults
      log global
  3. View logs by querying the rsyslog container using the docker logs command:

    $ sudo docker logs rsyslog

Example

hapee-lb.cfg:

global
  log rsyslog:514 local0

defaults
  log global

frontend fe_main
  bind :80
  default_backend be_main

backend be_main
  server web1 web1:8080 check

commands:

# Create Docker network
$ sudo docker network create -d bridge my-network

# Run web server container
$ sudo docker run -d --network my-network --name web1 \
    --restart unless-stopped jmalloc/echo-server

# Run Rsyslog container
$ sudo docker run -d --network my-network --name rsyslog \
    --restart unless-stopped jumanjiman/rsyslog

# Run HAProxy Enterprise container
$ sudo docker run -d --network my-network --name hapee \
    -p 80:80 -p 443:443 --restart unless-stopped \
    -v (pwd):/etc/hapee-2.1 \
    hapee-registry.haproxy.com/hapee-business:2.1r1