一般的时间滚动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>