本文共 2111 字,大约阅读时间需要 7 分钟。
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-M-d HH:mm:ss}%x[%5p %t](%c:%3L) %m%n" />
</layout>
</appender>
<!-- 输出日志到文件 每天一个文件 -->
<appender name="dailyRollingFile"
class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="info"></param>
<param name="ImmediateFlush" value="true"></param>
<param name="File" value="d:/logs/dailyRollingFile.log"></param>
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'"></param>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}-%m%n"></param>
</layout>
</appender>
<!-- 输出日志到文件 文件大小到达指定尺寸的时候产生一个新的文件 -->
<appender name="railyFile"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="d:/logs/railyFile.log"></param>
<param name="ImmediateFlush" value="true"/>
<param name="Threshold" value="info"></param>
<param name="Append" value="true"></param>
<param name="MaxFileSize" value="30KB"></param>
<param name="MaxBackupIndex" value="100"></param>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}-%m%n"></param>
</layout>
</appender>
<!--然后定义logger,只有定义了logger并引入的appender,appender才会生效 -->
<logger name="org.quartz">
<level value="error" />
</logger>
<logger name="org.springframework.cache">
<level value="info" />
</logger>
<logger name="org.apache">
<level value="error" />
</logger>
<logger name="com.opensymphony.xwork2">
<level value="error" />
</logger>
<!-- Do1平台日志 -->
<logger name="cn.com.do1">
<level value="debug" />
</logger>
<!-- 控制台输出日志 -->
<root>
<level value="info" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="dailyRollingFile" />
<appender-ref ref="railyFile" />
</root>
</log4j:configuration>
转载于:https://www.cnblogs.com/signheart/p/6597933.html