Log4j2没有将消息记录到rsyslog

时间:2017-08-10 11:58:24

标签: java log4j2 rsyslog

这是Log4j2的配置。日志消息未记录在rsyslog中。我不确定我做错了什么。

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
    <Syslog name="RFC5424" format="RFC5424" host="189.16.2.198" port="513"
            protocol="TCP" appName="api" includeMDC="true" mdcId="mdc"
            facility="SYSLOG" enterpriseNumber="18060" newLine="true"
            id="Application">            
    </Syslog>  
</Appenders>
<Loggers>
<Logger name="Logger" level="INFO" includeLocation="true" additivity="false">
        <appender-ref ref="RFC5424"/>
    </Logger>
</Loggers>
</Configuration>

在Configuration中添加status =“trace”后,它会显示以下日志

2017-08-11 01:02:21,211 main DEBUG Initializing configuration XmlConfiguration[location=E:\Projects\Web\build\resources\main\log4j2.xml]
2017-08-11 01:02:21,220 main DEBUG Installed script engines
2017-08-11 01:02:21,682 main DEBUG Oracle Nashorn Version: 1.8.0_112, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
2017-08-11 01:02:21,683 main DEBUG PluginManager 'Core' found 100 plugins
2017-08-11 01:02:21,684 main DEBUG PluginManager 'Level' found 0 plugins
2017-08-11 01:02:21,688 main DEBUG No scheduled items
2017-08-11 01:02:21,691 main DEBUG Building Plugin[name=property, class=org.apache.logging.log4j.core.config.Property].
2017-08-11 01:02:21,712 main TRACE TypeConverterRegistry initializing.
2017-08-11 01:02:21,713 main DEBUG PluginManager 'TypeConverter' found 23 plugins
2017-08-11 01:02:21,732 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.SyslogAppender].
2017-08-11 01:02:21,741 main DEBUG createAppender(host="189.16.2.198", port="513", protocol="TCP", SSL=null, connectTimeoutMillis="0", reconnectionDelayMillis="0", immediateFail="true", name="RFC5424", immediateFlush="true", ignoreExceptions="true", facility="SYSLOG", id="Application", enterpriseNumber="18060", includeMdc="true", mdcId="mdc", mdcPrefix="null", eventPrefix="null", newLine="true", newLineEscape="null", appName="api", messageId="null", mdcExcludes="null", mdcIncludes="null", mdcRequired="null", format="RFC5424", Filter=null, Configuration(E:\Projects\\Web\build\resources\main\log4j2.xml), charset="UTF-8", exceptionPattern="null", ={}, advertise="false")
2017-08-11 01:02:21,750 main DEBUG PluginManager 'Converter' found 44 plugins
2017-08-11 01:02:21,792 main DEBUG Starting TcpSocketManager TCP:189.16.2.198:513
2017-08-11 01:02:21,792 main DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2017-08-11 01:02:21,793 main DEBUG createAppenders(={RFC5424})
2017-08-11 01:02:21,793 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2017-08-11 01:02:21,798 main DEBUG createAppenderRef(ref="RFC5424", level="INFO", Filter=null)
2017-08-11 01:02:21,799 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig].
2017-08-11 01:02:21,806 main DEBUG createLogger(additivity="false", level="INFO", name="Logger", includeLocation="true", ={RFC5424}, ={}, Configuration(E:\Projects\Web\build\resources\main\log4j2.xml), Filter=null)
2017-08-11 01:02:21,808 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2017-08-11 01:02:21,809 main DEBUG createAppenderRef(ref="RFC5424", level="null", Filter=null)
2017-08-11 01:02:21,809 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2017-08-11 01:02:21,811 main DEBUG createLogger(additivity="null", level="INFO", includeLocation="null", ={RFC5424}, ={}, Configuration(E:\Projects\Web\build\resources\main\log4j2.xml), Filter=null)
2017-08-11 01:02:21,812 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
2017-08-11 01:02:21,813 main DEBUG createLoggers(={Logger, root})
2017-08-11 01:02:21,813 main DEBUG Configuration XmlConfiguration[location=E:\Projects\Web\build\resources\main\log4j2.xml] initialized
2017-08-11 01:02:21,813 main DEBUG Starting configuration XmlConfiguration[location=E:\Projects\Web\build\resources\main\log4j2.xml]
2017-08-11 01:02:21,814 main DEBUG Started configuration XmlConfiguration[location=E:\Projects\Web\build\resources\main\log4j2.xml] OK.
2017-08-11 01:02:21,815 main TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@30db5536...
2017-08-11 01:02:21,815 main TRACE DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
2017-08-11 01:02:21,815 main TRACE DefaultConfiguration stopping root LoggerConfig.
2017-08-11 01:02:21,816 main TRACE DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
2017-08-11 01:02:21,816 main TRACE DefaultConfiguration stopping remaining Appenders.
2017-08-11 01:02:21,816 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
2017-08-11 01:02:21,817 main TRACE DefaultConfiguration stopped 1 remaining Appenders.
2017-08-11 01:02:21,817 main TRACE DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
2017-08-11 01:02:21,817 main DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@30db5536 OK
2017-08-11 01:02:21,820 main TRACE Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector@7c7e73c5
2017-08-11 01:02:21,821 main TRACE Reregistering context (1/1): 'AsyncContext@73d16e93' org.apache.logging.log4j.core.async.AsyncLoggerContext@13cc0b90
2017-08-11 01:02:21,822 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93'
2017-08-11 01:02:21,823 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=StatusLogger'
2017-08-11 01:02:21,824 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=ContextSelector'
2017-08-11 01:02:21,826 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=Loggers,name=*'
2017-08-11 01:02:21,827 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=Appenders,name=*'
2017-08-11 01:02:21,829 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=AsyncAppenders,name=*'
2017-08-11 01:02:21,830 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=AsyncLoggerRingBuffer'
2017-08-11 01:02:21,831 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=Loggers,name=*,subtype=RingBuffer'
2017-08-11 01:02:21,837 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93
2017-08-11 01:02:21,855 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=AsyncLoggerRingBuffer
2017-08-11 01:02:21,857 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=StatusLogger
2017-08-11 01:02:21,859 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=ContextSelector
2017-08-11 01:02:21,863 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=Loggers,name=Logger
2017-08-11 01:02:21,864 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=Loggers,name=
2017-08-11 01:02:21,865 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext@73d16e93,component=Appenders,name=RFC5424
2017-08-11 01:02:21,871 main TRACE Using default SystemClock for timestamps.
2017-08-11 01:02:21,871 main TRACE Using DummyNanoClock for nanosecond timestamps.
2017-08-11 01:02:21,872 main DEBUG Reconfiguration complete for context[name=AsyncContext@73d16e93] at URI E:\Projects\Web\build\resources\main\log4j2.xml (org.apache.logging.log4j.core.async.AsyncLoggerContext@13cc0b90) with optional ClassLoader: null
2017-08-11 01:02:21,872 main DEBUG Shutdown hook enabled. Registering a new one.
2017-08-11 01:02:21,873 main DEBUG LoggerContext[name=AsyncContext@73d16e93, org.apache.logging.log4j.core.async.AsyncLoggerContext@13cc0b90] started OK.
2017-08-11 01:02:21,875 main TRACE Using default SystemClock for timestamps.
2017-08-11 01:02:21,876 main DEBUG AsyncLogger.ThreadNameStrategy=CACHED

看来,源和目标机器之间建立了TCP连接。

tcp        0      0 0.0.0.0:513                 0.0.0.0:*                   LISTEN      25481/rsyslogd
tcp        0      0 189.16.2.198:513            189.16.2.89:58701           ESTABLISHED 25481/rsyslogd
tcp        0      0 :::513                      :::*                        LISTEN      25481/rsyslogd

注意:在Windows防火墙级别启用513端口。

如果配置中有任何问题,请告诉我

0 个答案:

没有答案