]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: log: add support for logging to existing file descriptors
authorWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 06:34:59 +0000 (07:34 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 17:37:55 +0000 (18:37 +0100)
commit5a32ecc6cf035468f119a7556d64f5cb6e8d11d1
tree14d39e294224c8f3c2c532ca5410dbc16a1b2ba9
parent13ef7737227a07efa0d604d0e11a33cd08e926d2
MEDIUM: log: add support for logging to existing file descriptors

In certain situations it would be desirable to log to an existing file
descriptor, the most common case being a pipe between containers or
processes. The main issue with pipes is that using write() on them will
randomly truncate messages. But there is a trick. By using writev(), we
can atomically deliver or drop a message, which perfectly fits the
purpose. The only caveat is that large messages (4096 bytes on modern
operating systems) may be interleaved with messages from other processes
if using nbproc for example. In practice such messages are rare and most
of the time when users need such type of logging, the load is low enough
for a single process to be running so this is not really a problem.

This logging method thus uses unbuffered writev() calls and is uses more
CPU than if it used its own buffer with large writes at once, though this
is not a problem for moderate loads.

Logging to a file descriptor attached to a file also works with the side
effect that the process is significantly slowed down during disk accesses
and that it's not possible to rotate the file without restarting the
process. For this reason this option is not offered as a configuration
option, since it would confuse most users, but one could decide to
redirect haproxy's output to a file during debugging sessions. Two aliases
"stdout" and "stderr" are provided, but keep in mind that these are closed
by default in daemon mode.

When logging to a pipe or socket at a high enough rate, some logs will be
dropped and the number of dropped messages is reported in "show info".
doc/configuration.txt
src/log.c