Dav*_*eas 5 compression apache logging log4j2
如何仅压缩较旧的滚动文件而不是每次滚动时都进行压缩?(现在是每天)。以下配置仅每天滚动并在 60 天后删除压缩文件,但它每天都会压缩。
如果我必须调查最近 [X] 天的文件,我不想使用工具来解压缩它们......
<RollingRandomAccessFile name="file" fileName="${baseDir}/app-trace.log"
filePattern="${baseDir}/app-trace-%d{yyyy-MM-dd}.log.gz"
immediateFlush="false" append="true">
<PatternLayout pattern="%d %-5p [%t] %c - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
<DefaultRolloverStrategy max="91">
<Delete basePath="${baseDir}" maxDepth="2">
<IfFileName glob="*/app-trace*.log.gz">
<IfLastModified age="60d">
<IfAny>
<IfAccumulatedFileSize exceeds="1 GB"/>
<IfAccumulatedFileCount exceeds="10"/>
</IfAny>
</IfLastModified>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的问题,最终我自己实现了 DeleteAction,并将其附加到 DefaultRolloverStrategy,以便它在删除之前压缩所有内容。您可以在以下位置找到源代码:
https://github.com/lqbweb/log4j2-ZipDelete