我在同一个类路径上有两个jar文件,因此它们使用相同的log4j.xml。 xml文件所在的项目之一,按照我的预期滚动它的日志文件,但没有其他项目。
我已经将xml配置为使用1096K创建10个备份文件,但是当达到最大大小时,没有创建备份文件并且正在删除主日志文件。
的log4j.xml:
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%c.%M()]: %m %n"></param>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="logs/arqGUI.log" />
<param name="MaxFileSize" value="4096KB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%c.%M()]: %m %n"></param>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<appender name="FILE_SERVICE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="logs/arqService.log" />
<param name="MaxFileSize" value="1096KB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%c.%M()]: %m %n"></param>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<logger name="com.emp.sin.orcmultemp.service" additivity="false" >
<level value="WARN" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE_SERVICE" />
</logger>
<logger name="org.springframework">
<level value="WARN" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</logger>
<logger name="org.hibernate">
<level value="WARN" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</logger>
<root>
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
使用log4j:
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class MainClass {
private static final Logger LOGGER = LogManager.getLogger(MainClass.class);
LOGGER.info("TEST");
}