log4j基本配置

log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

	<appender name="A1" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern"
				value="%d{yyyy-MM-dd HH:mm:ss} [%c{2}]-[%p] %m%n" />
		</layout>
		<!--过滤器设置输出的级别-->
		<filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="levelMin" value="DEBUG" />
			<param name="levelMax" value="INFO" />
			<param name="AcceptOnMatch" value="true" />
		</filter>
	</appender>
	<!-- 平台服务 -->
	<appender name="service"
		class="org.apache.log4j.DailyRollingFileAppender">
		<param name="File" value="E:/log/service.log" />
		<param name="DatePattern" value="'.'yyyy-MM-dd'.log'" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern"
				value="%d{yyyy-MM-dd HH:mm:ss} [%c{3\}]-[%p] %m%n" />
		</layout>
	</appender>

	<logger additivity="false" name="com.dao">
		<level value="INFO" />
		<appender-ref ref="A1" />
		<appender-ref ref="service" />
	</logger>

</log4j:configuration>


log4j.porperties
#ConsoleAppender
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS}- %l%m%n

#FileAppender
log4j.appender.file = org.apache.log4j.FileAppender
log4j.appender.file.File = d:\\a.html
log4j.appender.file.layout=org.apache.log4j.HTMLLayout

log4j.rootLogger = error,stdout,file






你可能感兴趣的:(log4j)