我们正在从log4j1.x转移到log4j2
将属性文件更改为xml文件以支持log4j2
以下是我们正在使用的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
<Appenders>
<RollingFile name="syslog" fileName="/var/log/stor/gui/gui.log" filePattern="/var/log/stor/gui/gui-%d{MM-dd-yyyy}-%i.log" append="true">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Filters>
<!-- Now deny warn, error and fatal messages -->
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- This filter accepts info, warn, error, fatal and denies debug/trace -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="16 MB"/>
</Policies>
<DefaultRolloverStrategy max="1"/>
</RollingFile>
</Appenders>
<appenders>
<RollingFile name="requestUrilog" fileName="/var/log/stor/gui/requestUrilog.log" filePattern="/var/log/stor/gui/requestUrilog-%d{MM-dd-yyyy}-%i.log" append="true">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Filters>
<!-- Now deny warn, error and fatal messages -->
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- This filter accepts info, warn, error, fatal and denies debug/trace -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="8 MB"/>
</Policies>
<DefaultRolloverStrategy max="4"/>
</RollingFile>
</appenders>
<appenders>
<RollingFile name="userlog" fileName="/var/log/stor/gui/userlog.log" filePattern="/var/log/stor/gui/userlog-%d{MM-dd-yyyy}-%i.log" append="true">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Filters>
<!-- Now deny warn, error and fatal messages -->
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- This filter accepts info, warn, error, fatal and denies debug/trace -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="8 MB"/>
</Policies>
<DefaultRolloverStrategy max="4"/>
</RollingFile>
</appenders>
<Loggers>
<Logger name="com.tms.gui.sys" additivity="false" level="info">
<AppenderRef ref="syslog"/>
</Logger>
<Logger name="com.tms.gui.requestUri" additivity="false" level="info">
<AppenderRef ref="requestUrilog"/>
</Logger>
<Logger name="com.tms.gui.user" additivity="false" level="info">
<AppenderRef ref="userlog"/>
</Logger>
<Root level="info">
<AppenderRef ref="syslog"/>
</Root>
</Loggers>
</Configuration>
下面是我们为错误获取的debuf信息
DEBUG Found factory method [createLoggers]: public static org.apache.logging.log4j.core.config.Loggers org.apache.logging.log4j.core.config.LoggersPlugin.createLoggers(org.apache.logging.log4j.core.config.LoggerConfig[]).
2016-01-14 12:40:14,757 localhost-startStop-1 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers with params(={com.tms.gui.sys, com.tms.gui.requestUri, com.tms.gui.user, root})
2016-01-14 12:40:14,758 localhost-startStop-1 DEBUG Built Plugin[name=loggers] OK from factory method.
2016-01-14 12:40:14,758 localhost-startStop-1 ERROR Unable to locate appender requestUrilog for logger com.tms.gui.requestUri
2016-01-14 12:40:14,758 localhost-startStop-1 ERROR Unable to locate appender syslog for logger
2016-01-14 12:40:14,758 localhost-startStop-1 ERROR Unable to locate appender syslog for logger com.tms`enter code here`.gui.sys
2016-01-14 12:40:14,759 localhost-startStop-1 DEBUG Configuration XmlConfiguration[location=/opt/stor/gui/www/WEB-INF/classes/log4j2.xml] initialized
请指导我们我们做错了什么
答案 0 :(得分:1)
ThresholdFilter检查日志事件的级别是否与指定级别相同或更具体。因此检查级别的过滤器&#34;警告&#34;在匹配上,DENY也会拒绝错误和致命,使下两个过滤器变得不必要。
您能提供用于创建追加者的调试信息吗?由于在创建/ var / log目录中的文件时出现权限问题,因此在创建它们时遇到问题可能无法找到appender。