Petre Popescu
Petre Popescu

Reputation: 2002

Syslog-ng and Log4j2 configuration

I am trying to write to Syslog from Log4J2 and I am having problems connecting to Syslog-ng. I believe the port is the problem, but I could not find anywhere in the syslog-ng.conf file what is the port. This is my Log4j2 XML file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="com.payon.logging.v2">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ABSOLUTE} [%x][%X{MASKEDSERVLETPATH}] %5p %c{1}: %k%n"/>
        </Console>
        <Syslog name="Syslog" host="localhost" port="514" protocol="TCP">
            <PatternLayout pattern="%d{ABSOLUTE} [%x][%X{MASKEDSERVLETPATH}] %5p %c{1}: %m%n"/>
        </Syslog>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="Syslog"/>
        </Root>
    </Loggers>
</Configuration>

Syslog-ng is running:

service syslog-ng status
● syslog-ng.service - System Logger Daemon
   Loaded: loaded (/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-02-15 10:08:28 CET; 31min ago
     Docs: man:syslog-ng(8)
 Main PID: 745 (syslog-ng)
    Tasks: 1 (limit: 4915)
   Memory: 11.9M
   CGroup: /system.slice/syslog-ng.service
           └─745 /usr/sbin/syslog-ng -F

However, I am getting this error: ERROR TcpSocketManager (TCP:localhost:514) caught exception and will continue: java.io.IOException: Unable to create socket for localhost at port 514 using ip addresses and ports

What am I missing in the configuration? With Log4j1, I did not have to provide a port

Upvotes: 0

Views: 1195

Answers (1)

MrAnno
MrAnno

Reputation: 754

<Syslog name="Syslog" host="localhost" port="514" protocol="TCP"> requires a network source that needs to be specified in the syslog-ng configuration, for example:

source { network(port(514)); };

Alternatively, default-network-drivers() can be used, which sets good defaults (TCP/UDP 514 and 601):

log {
    source { default-network-drivers(); };
    # ...
};

Upvotes: 2

Related Questions