Syslog-ng 和 Log4j2 配置
Syslog-ng and Log4j2 configuration
我正在尝试从 Log4J2 写入 Syslog,但在连接到 Syslog-ng 时遇到问题。我相信端口是问题所在,但我在 syslog-ng.conf 文件的任何地方都找不到端口是什么。
这是我的 Log4j2 XML 文件:
<?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 是 运行:
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
但是,我收到此错误: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
我在配置中缺少什么?使用 Log4j1,我不必提供端口
<Syslog name="Syslog" host="localhost" port="514" protocol="TCP">
需要在syslog-ng配置中需要指定的网络源,例如:
source { network(port(514)); };
或者,可以使用 default-network-drivers()
,这会设置良好的默认值(TCP/UDP 514 和 601):
log {
source { default-network-drivers(); };
# ...
};
我正在尝试从 Log4J2 写入 Syslog,但在连接到 Syslog-ng 时遇到问题。我相信端口是问题所在,但我在 syslog-ng.conf 文件的任何地方都找不到端口是什么。 这是我的 Log4j2 XML 文件:
<?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 是 运行:
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
但是,我收到此错误: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
我在配置中缺少什么?使用 Log4j1,我不必提供端口
<Syslog name="Syslog" host="localhost" port="514" protocol="TCP">
需要在syslog-ng配置中需要指定的网络源,例如:
source { network(port(514)); };
或者,可以使用 default-network-drivers()
,这会设置良好的默认值(TCP/UDP 514 和 601):
log {
source { default-network-drivers(); };
# ...
};