Sample log4j.xml

Sample log4j.xml
Here is a sample log4j.xml for development purposes.
1、
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
    </layout>
    </appender>

    <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
    </appender>

    <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/path/output.log"/>
    <param name="MaxFileSize" value="1MB"/>
    <param name="MaxBackupIndex" value="100"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
    </layout>
    </appender>

    <root>
    <priority value="info"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="ASYNC"/>
    </root>
    </log4j:configuration>



2、
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
	debug="false">
	<!-- 
		<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
		<param name="Target" value="System.out" />
		<param name="Threshold" value="DEBUG" />
		<layout class="org.apache.log4j.PatternLayout">
		<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
		</layout>
		</appender>
	-->
	<appender name="UNIWORK"
		class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="uniwork.log" />
		<param name="Append" value="true" />
		<param name="MaxFileSize" value="1024KB" />
		<param name="MaxBackupIndex" value="10" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern"
				value="%d %p [%c] - %m%n" />
		</layout>
	</appender>
	<!-- 
	<appender name="UNIWORK" class="org.apache.log4j.FileAppender">
		<param name="File" value="uniwork.log" />
		<param name="Append" value="true" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
		</layout>
	</appender>
	 -->
	<!-- 
		<appender name="EXAM" class="org.apache.log4j.FileAppender">
		<param name="File" value="D:/logs/exam.log" />
		<param name="Append" value="true" />
		<layout class="org.apache.log4j.PatternLayout">
		<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
		</layout>
		</appender>
		<category name="com.mochasoft">
		<priority value="DEBUG" />
		<appender-ref ref="EXAM" />
		</category>
	-->
	<root>
		<level value="DEBUG" />
		<!-- <appender-ref ref="CONSOLE" /> -->
		<appender-ref ref="UNIWORK" />
	</root>
</log4j:configuration>

你可能感兴趣的:(log4j,xml)