Using Syslog's unix socket with Log4J2

2019-04-07 04:05发布

问题:

I would like to send the logs of an application on a rsyslog server using the client protocol : Unix socket. Both application and rsyslog server are on the same machine.

I've been comparing different logging tools : Log4J, Logback and Log4J2.

Log4J's Syslog appender doesn't permit it natively. A solution is to use Syslog4J and configure our Syslog4JAppender this way :

<appender name="mySyslogAppender" class="org.productivity.java.syslog4j.impl.log4j.Syslog4jAppender">
    <param name="protocol" value="unix_socket" />
    ...
</appender>

Same as Log4J, Logback's Syslog appender doesn't permit it natively. A solution is to use Syslog4J and logback-syslog4j tool, and configure our appender this way :

<appender name="mySyslogAppender" class="com.papertrailapp.logback.Syslog4jAppender">
    <syslogConfig class="org.productivity.java.syslog4j.impl.unix.socket.UnixSocketSyslogConfig">
            ...
    </syslogConfig>
</appender>

Now I'm looking for a solution for Log4J 2, but I didn't find any. Do you know one ? Do these tools will include natively this functionality ?