如何在每日时间进行追加?

时间:2018-02-27 09:09:37

标签: java logback slf4j

我有一个基于尺寸和时间的滚动政策的追随者,任何人都可以告诉如何在日常生产中进行滚动尺寸并不重要吗?

<appender name="POS"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${log.folder}/POS/terminal-pos-%d{yyyy-MM-dd}.log
        </fileNamePattern>
        <maxHistory>30</maxHistory>
        <totalSizeCap>1GB</totalSizeCap>
    </rollingPolicy>
    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>10MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>TERMINAL ID [%X{terminalId}] %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
    </encoder>
</appender>

1 个答案:

答案 0 :(得分:0)

基于时间的滚动政策:

<appender name="POS" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${log.folder}/POS/terminal-pos-%d{yyyy-MM-dd}.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <FileNamePattern>>${log.folder}/POS/terminal-pos-%d{yyyy-MM-dd}.log.%i.gz</FileNamePattern>
        <MaxHistory>30</MaxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>TERMINAL ID [%X{terminalId}] %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
    </encoder>
</appender>

您可以在启动日志中检查滚动策略:

INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern...
INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to ...

基于时间和规模的滚动政策

<appender name="POS" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${log.folder}/POS/terminal-pos-%d{yyyy-MM-dd}.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <FileNamePattern>>${log.folder}/POS/terminal-pos-%d{yyyy-MM-dd}.log.%i.gz</FileNamePattern>
        !-- rollover daily -->
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches 50MB -->
            <maxFileSize>50MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
        <MaxHistory>30</MaxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>TERMINAL ID [%X{terminalId}] %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
    </encoder>
</appender>