首页 > 代码库 > log4j2j配置

log4j2j配置

maven依赖

<properties>
<sl4j.version>1.7.7</sl4j.version>
<log4j2.version>2.1</log4j2.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

配置:(只有trace模式下,才能打印出sql的结果集)
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="60">

<properties>
<property name="logPath">${profiles.logpath}</property>
</properties>

<Appenders>

<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%X{hdsf.traceid}] [%X{hdsf.appid}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c:%L - %msg%n" />
</Console>

<RollingFile name="root" filename="${logPath}/runtine.log" filepattern="${logPath}/%d{yyyyMMdd}-%i-root.log">
<PatternLayout pattern="[%X{hdsf.traceid}] [%X{hdsf.appid}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c:%L - %msg%n" />
<Policies>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>

</Appenders>


<Loggers>

<logger name="org.springframework.web.method.support" level="INFO"></logger>
<logger name="org.springframework.context.event" level="INFO"></logger>
<logger name="org.springframework.beans.factory.xml" level="INFO"></logger>
<logger name="org.springframework.context.annotation" level="INFO"></logger>
<logger name="org.springframework.web.servlet.resource" level="INFO"></logger>
<logger name="org.apache.velocity" level="INFO"></logger>
<logger name="org.springframework.beans" level="INFO"></logger>

<logger name="org.springframework.core" level="INFO"></logger>
<logger name="org.springframework.web" level="INFO"></logger>

<logger name="org.apache.cxf" level="INFO"></logger>

<Root level="trace">
<AppenderRef ref="Console" />
<AppenderRef ref="root" />
</Root>

</Loggers>
</Configuration>

log4j2j配置