我刚从log4j 1.x更新到log4j2。在第一版中,每件事都很好。现在更新到log4j2后,它没有记录任何东西。我正在粘贴下面的代码。任何人请帮帮我
这是我的依赖
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.0-beta9</version>
<type> jar</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta9</version>
<type> jar</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta9</version>
<type> jar</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.0-beta9</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0-beta9</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-taglib</artifactId>
<version>2.0-beta9</version>
</dependency>
这是我的log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<console name="Console" target="SYSTEM_OUT" includeLocation="true">
<PatternLayout pattern="%d %-5p [%t] [%c:%L] %m%n"/>
</console>
<RollingRandomAccessFile name="Rolling" fileName="${sys:DOC_ROOT}/logs/UILogs-${sys:SERVER_NAME}-${sys:SERVER_ID}-${sys:SERVER_TYPE}.log"
filePattern="${sys:DOC_ROOT}/logs/UILogs-${sys:SERVER_NAME}-${sys:SERVER_ID}-${sys:SERVER_TYPE}-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="%d %-5p [%t] [%c:%L] %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
<DefaultRolloverStrategy max="180" compressionLevel="9"/>
</RollingRandomAccessFile>
<Async name="dev">
<AppenderRef ref="DevSMTP" level="fatal"/>
<AppenderRef ref="Console" level="debug"/>
<AppenderRef ref="Rolling" level="debug"/>
</Async>
<Async name="test">
<AppenderRef ref="TestSMTP" level="fatal"/>
<AppenderRef ref="Console" level="debug"/>
<AppenderRef ref="Rolling" level="debug"/>
</Async>
<Async name="prod">
<AppenderRef ref="ProdSMTP" level="fatal"/>
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="Rolling" level="info"/>
</Async>
<Async name="local">
<AppenderRef ref="DevSMTP" level="fatal"/>
<AppenderRef ref="Console" level="debug"/>
<AppenderRef ref="Rolling" level="debug"/>
</Async>
<Async name="">
<AppenderRef ref="ProdSMTP" level="fatal"/>
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="Rolling" level="info"/>
</Async>
<Async name="">
<AppenderRef ref="TestSMTP" level="fatal"/>
<AppenderRef ref="Console" level="debug"/>
<AppenderRef ref="Rolling" level="debug"/>
</Async>
<Async name="">
<AppenderRef ref="ProdSMTP" level="fatal"/>
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="Rolling" level="info"/>
</Async>
<Async name="lib">
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="Rolling" level="info"/>
</Async>
</Appenders>
<Loggers>
<Root level="debug" additivity="false">
<AppenderRef ref="${sys:SERVER_TYPE}"/>
</Root>
<root level="error">
<appender-ref ref="Console"/>
</root>
<Logger name="org.apache.ibatis" additivity="false">
<AppenderRef ref="lib"/>
</Logger>
<Logger name="java.sql" additivity="false">
<AppenderRef ref="lib"/>
</Logger>
<Logger name="RollingRandomAccessFile" additivity="true">
<AppenderRef ref="Rolling"/>
</Logger>
<logger name="com.foo.Bar" level="trace">
<appender-ref ref="Console"/>
</logger>
</Configuration>
答案 0 :(得分:3)
配置中有几件事需要解决:
<强>依赖关系:强>
<type>
和jar
之间有一个空格''字符。 (不确定这是否会导致任何问题)。Log4j2.xml配置:
Async
个追加者。他们必须有名字。<Loggers>
元素没有结束</Loggers>
标记。这可能是最大的问题。答案 1 :(得分:0)
您是否收到任何相关错误?例如,如果是错误:“ERROR StatusLogger无法使用SimpleLogge找到日志记录实现”请尝试使用此link来解决日志记录问题。