log4j配置

1. pom.xml

<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.2</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.2</version>
		</dependency>

 

 

 

2. 在src/main/resources根目录下建一个log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
	<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n" />
		</layout>
	</appender>
	<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
		<param name="file" value="${loggingRoot}/${server.name}/logs/${server.name}.log" />
		<!-- Keep one backup file -->
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n" />
		</layout>
	</appender>
	<!-- specify the logging level for loggers from other libraries -->
	<logger name="com.opensymphony">
		<level value="${loggingLevel}" />
	</logger>
	<logger name="org.apache.struts2">
		<level value="${loggingLevel}" />
	</logger>
	<logger name="org.springframework">
		<level value="${loggingLevel}" />
	</logger>
	<logger name="org.apache.ibatis">
		<level value="${loggingLevel}" />
	</logger>
	<logger name="com.opensymphony.module.sitemesh">
		<level value="${loggingLevel}" />
	</logger>
	<logger name="org.quartz">
		<level value="${loggingLevel}"/>
	</logger>
	<logger name="net.spy.memcached">
		<level value="${loggingLevel}"/>
	</logger>
	<logger name="org.dbunit">
		<level value="INFO"/>
	</logger>
	
	<!-- for mybatis -->
	<logger name="com.vlt">
		<level value="DEBUG"/>
	</logger>
	<logger name="org.apache.ibatis">
		<level value="DEBUG"/>
	</logger>
	
	<!-- for all other loggers log only info and above log messages -->
	<root>
		<priority value="${loggingLevel}" />
		<appender-ref ref="FILE"/>
		<appender-ref ref="STDOUT"/>
	</root>
</log4j:configuration> 

 

 

3. 在filter-dev.properties中指定log级别

## log configuration
loggingRoot=.
loggingLevel=WARN

 

 

级别顺序(低到高): DEBUG < INFO < WARN < ERROR < FATAL

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值