Last updated: November 29, 2024

<span aria-hidden="true" id="haproxy-logging"></span>

# HAProxy logging

![Kevin van Zonneveld](/assets/images/teammates/avatar-kvz-4.jpg?dpl=dpl_3fBRD5jmFtSDABLXGJJyXU1nVXf8)

**Kevin van Zonneveld**

Co-founder · Amsterdam, The Netherlands · Show bio

[](https://x.com/kvz)[](https://github.com/kvz)

At [Transloadit](/index.md), we use [HAProxy⁠](https://www.haproxy.org/) "The Reliable, High Performance TCP/HTTP Load Balancer", so that we can offer different services on one port. For instance, depending on the hostname, a request to port 80 can be routed to either[Node.js⁠](https://nodejs.org/) (in case of [api.transloadit.com⁠](https://api.transloadit.com)) or[Nginx⁠](https://nginx.net/) (in case of [www.transloadit.com](/index.md)). HAProxy has been good to us and setting it up was a breeze. But getting HAProxy to log on[Ubuntu⁠](https://www.ubuntu.com/) Lucid has proven harder than I thought. All of the tutorials I found either didn't cover logging or contained deprecated information. Google suddenly stopped being my friend.

<span aria-hidden="true" id="haproxy-wants-to-log"></span>

## HAProxy wants to log

For performance and maintenance reasons, HAProxy doesn't log directly to files. Instead, it wants to log to a syslog server. This is a separate Linux daemon with which most servers are already equipped. HAProxy, however, requires it to listen on UDP port 514 and that is usually not enabled.

A syslog server receives log entries, decides which ones are interesting and writes those to disk in a highly optimized manner. These aspect can all be configured to your liking.

If we look at the top of your current `/etc/haproxy/haproxy.cfg` file, we may find something like:

```bash
global
maxconn 10000
ulimit-n 65536
log 127.0.0.1 local0
log 127.0.0.1 local1 notice

```

As you can see, `127.0.0.1` is where it will try to find a syslog server to log to. On Ubuntu Lucid, the default syslog daemon is[rsyslogd⁠](https://manpages.ubuntu.com/manpages/hardy/man8/rsyslogd.8.html), so let's make that one accept HAProxy log entries.

<span aria-hidden="true" id="rsyslogd-welcomes-haproxy"></span>

## Rsyslogd welcomes HAProxy

The majority of Google results that cover logging with HAProxy told me to change the`/etc/default/rsyslog` file, but that file is now completely ignored under the new[upstart⁠](https://upstart.ubuntu.com/) system. Moreover, even if you make HAProxy adhere to the default file (yep, I tried), it will force rsyslogd into compatibility mode. That is not only a shame, but also unnecessary as it turns out.

By using the following config lines:

```bash
$ModLoad imudp
$UDPServerRun 514

```

rsyslogd will open up its UDP port.

Where to put these lines, you say? Well, if you are only using the UDP syslog port for the HAProxy service, you can put/uncomment the lot in just one `/etc/rsyslog.d/haproxy.conf` file:

```bash
# .. otherwise consider putting these two in /etc/rsyslog.conf instead:
$ModLoad imudp
$UDPServerRun 514

# ..and in any case, put these two in /etc/rsyslog.d/haproxy.conf:
local0.* -/var/log/haproxy_0.log
local1.* -/var/log/haproxy_1.log

```

Now do a quick:

```bash
restart rsyslog

```

And you're done. Check for HAProxy logs in:

```bash
tail -f /var/log/haproxy*.log

```

And don't forget to tweak the debug level in `/etc/haproxy/haproxy.cfg`.

Happy logging!

[#howto](/blog/tags/howto.md)[#infrastructure](/blog/tags/infrastructure.md)[#ops](/blog/tags/ops.md)

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
