Log4j.xml配置(rolling示例)
Log4j.xml配置(很详细)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<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\:SSS}][%p](%c{1}\:%L) - %m%n"/>
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="../logs/jdbc_agent.log"/>
<param name="Append" value="true" />
<param name="MaxBackupIndex" value="10" />
<param name="MaxFileSize" value="100MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH\:mm\:ss\:SSS}][%p](%c{1}\:%L) - %m%n"/>
</layout>
</appender>
<appender name="ERROR_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="../logs/jdbc_agent_error.log"/>
<param name="Append" value="true" />
<param name="MaxBackupIndex" value="10" />
<param name="MaxFileSize" value="50MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH\:mm\:ss\:SSS}][%p](%c{1}\:%L) - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="ERROR" />
<param name="LevelMax" value="ERROR" />
</filter>
</appender>
<logger name="com.ai.toptea.collection" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ERROR_FILE"/>
</logger>
<root>
<priority value="INFO"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ERROR_FILE"/>
</root>
</log4j:configuration>