fluent/fluent-logger-java

Add Support For Unix Domain Sockets

pgiblock opened this issue · 1 comments

It would be nice if this logger would support Unix Domain Sockets as the target instead of only (host, port) inet addresses. UnixDomainSocketAddress was added in Java 16. However, this library need not depend on that if SocketAddress can be supplied to getLogger() which has been around since 1.4.

This feature would be particularly useful for container environments such as Docker because some not very nice tricks are required for a container to connect to a host socket. Note that Unix domain sockets are supported by Fluentd and Fluent-Bit.

For anyone else running into this problem, there is a workaround that I find cleaner than running with host networking or having to address the host by address/hostname, bind on the interface, and implement firewall rules. It requires running a little forwarder to "proxy" the data from docker-lived networking to the host-lived domain socket:

docker run -h fluent -v /var/run/fluent-bin.sock:/sock fluent/fluent-bit:1.9 \
    -i forward -o forward -p unix_path=/sock

You'll likely need to place this on the right network(s), but docker containers can now forward to the hostname "fluent" and records will appear on the actual host.