在Log4j2中定义TimeBasedTriggeringPolicy的日期/时间模式的位置

mrb*_*ela 5 java configuration logging log4j log4j2

我是Log4j2的新手,想要使用RollingFileAppender.进一步作为翻转,我想使用TimeBaseTriggeringPolicy:

一旦日期/时间模式不再适用于活动文件,TimeBasedTriggeringPolicy将导致翻转.

在上面的网站上有一个这样的TimeBasedTriggeringPolicy示例:

<?xml version="1.0" encoding="UTF-8"?>    
<Configuration status="warn" name="MyApp" packages="">
    <Appenders>
        <RollingFile name="RollingFile" fileName="logs/app.log"
    filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="error">
            <AppenderRef ref="RollingFile"/>
        </Root>
    </Loggers>
</Configuration>
Run Code Online (Sandbox Code Playgroud)

在定义的"日期/时间模式"上方的配置中,确定活动文件是否适用于它?

谢谢你的帮助!

Rem*_*pma 8

那是filePattern.在你的配置中:

filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
Run Code Online (Sandbox Code Playgroud)

上面最精细的时间单位是dd(天),因此它将在午夜每天翻转.