logback实时动态文件名

一般的时间滚动log配置是

<appender name="logAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/log_%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%msg%n</pattern>
</encoder>
</appender>

如果要实时生成带时间标记的log文件,而不是第二天才能生成,那么只要去掉<file>标签 就可以了

<appender name="logAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_PATH}/log_%d{yyyy-MM-dd}.log</fileNamePattern>
    </rollingPolicy>
    <encoder>
        <charset>UTF-8</charset>
        <pattern>%msg%n</pattern>
    </encoder>
</appender>

 

posted @ 2019-08-07 16:28  卡拉迦迪斯  阅读(2135)  评论(0编辑  收藏  举报