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="STDOUT" class="org.apache.log4j.ConsoleAppender">
		  <layout class="org.apache.log4j.PatternLayout">
 	 		 <param name="ConversionPattern"
				    value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
		  </layout>
	 </appender>

 	<appender name="ROLLINGFILE" class="org.apache.log4j.DailyRollingFileAppender">
		  <param name="DatePattern" value=".yyyy-MM-dd" />
		  <param name="File" value="log/test.log" />
		  <param name="Encoding" value="GBK" />
		  <layout class="org.apache.log4j.PatternLayout">
 			  <param name="ConversionPattern"
  				  value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
		  </layout>
	 </appender>

	 <!--设定级别为debug的配置信息-->
	 <appender name="DEBUG"	  class="org.apache.log4j.DailyRollingFileAppender">
		  <param name="DatePattern" value=".yyyy-MM-dd" />
		  <param name="File" value="log/test_debug.log" />
		  <param name="Append" value="true" />
		  <layout class="org.apache.log4j.PatternLayout">
			   <param name="ConversionPattern"
					value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
		  </layout>
		  <filter class="org.apache.log4j.varia.LevelRangeFilter">
			   <param name="LevelMin" value="DEBUG" />
			   <param name="LevelMax" value="DEBUG" />
		  </filter>
	 </appender>

	 <!--设定级别为info的配置信息-->
	 <appender name="INFO"  class="org.apache.log4j.DailyRollingFileAppender">
		  <param name="DatePattern" value=".yyyy-MM-dd" />
		  <param name="File" value="log/test_info.log" />
		  <param name="Append" value="true" />
		  <layout class="org.apache.log4j.PatternLayout">
			   <param name="ConversionPattern"
				    value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
		  </layout>
 		 <filter class="org.apache.log4j.varia.LevelRangeFilter">
			   <param name="LevelMin" value="INFO" />
			   <param name="LevelMax" value="INFO" />
		  </filter>
	 </appender>

	 <!--设定级别为warn的配置信息-->
	 <appender name="WARN"  class="org.apache.log4j.DailyRollingFileAppender">
		  <param name="DatePattern" value=".yyyy-MM-dd" />
		  <param name="File" value="log/test_warn.log" />
		  <param name="Append" value="true" />
		  <layout class="org.apache.log4j.PatternLayout">
			   <param name="ConversionPattern"
					    value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
		  </layout>
		  <filter class="org.apache.log4j.varia.LevelRangeFilter">
			   <param name="LevelMin" value="WARN" />
			   <param name="LevelMax" value="WARN" />
		  </filter>
	 </appender>

	 <!--设定级别为error的配置信息-->
	 <appender name="ERROR"	  class="org.apache.log4j.DailyRollingFileAppender">
		  <param name="File" value="log/test_error.log" />
		  <param name="Append" value="true" />
		  <layout class="org.apache.log4j.PatternLayout">
			   <param name="ConversionPattern"
				    value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
		  </layout>
		  <filter class="org.apache.log4j.varia.LevelRangeFilter">
			   <param name="LevelMin" value="ERROR" />
			   <param name="LevelMax" value="ERROR" />
		  </filter>
	 </appender>

	 <!--设定级别为fatal的配置信息-->
	 <appender name="FATAL"  class="org.apache.log4j.DailyRollingFileAppender">
		  <param name="File" value="log/test_fatal.log" />
		  <param name="Append" value="true" />
		  <layout class="org.apache.log4j.PatternLayout">
			   <param name="ConversionPattern"
					    value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] [%p] [%m] " />
 		 </layout>
		  <filter class="org.apache.log4j.varia.LevelRangeFilter">
			   <param name="LevelMin" value="FATAL" />
			   <param name="LevelMax" value="FATAL" />
		  </filter>
	 </appender>

	 <!--设定不同包中类的日志级别-->
	 <logger name="com.test">
		  <level value="DEBUG" />
	 </logger>
	 <logger name="org.apache">
		  <level value="ERROR" />
	 </logger>
	 <logger name="org.springframework">
		  <level value="ERROR" />
	 </logger>

	 <!--默认级别,需要输出哪种类型日志,就写哪种类型-->
	 <root>
		  <level value="DEBUG" />
		  <appender-ref ref="ROLLINGFILE" />
		  <appender-ref ref="STDOUT" />
		  <appender-ref ref="DEBUG" />
		  <appender-ref ref="INFO" />
		  <appender-ref ref="WARN" />
		  <appender-ref ref="ERROR" />
		  <appender-ref ref="FATAL" />
	 </root>
</log4j:configuration>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
	<appender name="myFile" class="org.apache.log4j.FileAppender">
		<param name="File" value="c:/output.log" />
		<param name="Append" value="true" />
		<param name="MaxBackupIndex" value="10" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%p (%c:%L)- %m%n" />
		</layout>
	</appender>

	<appender name="console" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern"
				value="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p [%c-%L] - %m%n" />
		</layout>
	</appender>

	<root>
		<level value="info" />
		<appender-ref ref="console" />
		<appender-ref ref="myFile" />
	</root>
</log4j:configuration>


你可能感兴趣的:(Log4j.xml备忘)