我有一个用于自定义日志记录的log4.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Console appender -->
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="<%-4d{DATE}> <%-4p> <%t> <%m> %n" />
</layout>
</appender>
<!-- File appender -->
<appender name="FileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="threshold" value="INFO"/>
<param name="File" value="test/logs/app.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="64MB" />
<param name="MaxBackupIndex" value="2" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="<%-4d{DATE}> <%-5p> <%t> <%m> %n" />
</layout>
</appender>
<root>
<priority value="INFO" />
<appender-ref ref="FileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4j:configuration>
我需要将此转换为log4j2并提出以下内容但我不确定这是否正确
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<!-- Console appender -->
<Parameters>
<param name="MaxBackupIndex" value="2"/>
</Parameters>
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="<%-4d{DATE}> <%-4p> <%t> <%m> %n"/>
</Console>
<!-- File appender -->
<RollingFile name="DAILY_LOG" fileName="test/logs/app.log"
filePattern="app.log.%d{yyyy-MM-dd-hh-mm}.gz"
>
<PatternLayout pattern="<%-4d{DATE}> <%-5p> <%t> <%m> %n"/>
<Policies>
<SizeBasedTriggeringPolicy size="64MB" />
<TimeBasedTriggeringPolicy interval="1"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="org.apache.log4j.xml" level="info"/>
<Root level="info">
<AppenderRef ref="ConsoleAppender"/>
<AppenderRef ref="FileAppender"/>
</Root>
</Loggers>
</Configuration>
任何人都知道我是否正确或在正确的轨道上?它似乎没有工作
答案 0 :(得分:0)
如果你想每天滚动它,那么你就不应该使用带有小时和分钟的文件模式。但是,如果您确实希望文件包含小时和分钟,则使用CronTriggeringPolicy而不是TimeBasedTriggeringPolicy。