https://blog.csdn.net/u010128608/article/details/76618263
https://blog.csdn.net/zhuyucheng123/article/details/21524457
<!-- 按时间回滚的同时,按文件大小来回滚 -->
1 <appender name="FILE" class= "ch.qos.logback.core.rolling.RollingFileAppender"> 2 <!-- 支持多JVM同时操作同一个日志文件 --> 3 <prudent>true</prudent> 4 <!-- 按天来回滚,如果需要按小时来回滚,则设置为{yyyy-MM-dd_HH} --> 5 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 6 <fileNamePattern>/opt/log/testC.%d{yyyy-MM-dd}.%i.log</fileNamePattern> 7 <!-- 如果按天来回滚,则最大保存时间为1天,1天之前的都将被清理掉 --> 8 <maxHistory>30</maxHistory> 9 <!-- 按时间回滚的同时,按文件大小来回滚 --> 10 <timeBasedFileNamingAndTriggeringPolicy 11 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 12 <maxFileSize>100MB</maxFileSize> 13 </timeBasedFileNamingAndTriggeringPolicy> 14 </rollingPolicy> 15 16 <!-- 日志输出格式 --> 17 <layout class="ch.qos.logback.classic.PatternLayout"> 18 <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} 19 -%msg%n</Pattern> 20 </layout> 21 </appender>
// 每天生成一个
1 <appender name="FILE2" class="ch.qos.logback.core.rolling.RollingFileAppender"> 2 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 3 <!-- <fileNamePattern>/diskb/tongji/apache-tomcat-9.0.12/bin/cargoweblogs/statisticsVisit.%d{yyyy-MM-dd}.log</fileNamePattern> --> 4 <fileNamePattern>cargoweblogs/statisticsVisit.%d{yyyy-MM-dd}.log</fileNamePattern> 5 <maxHistory>1</maxHistory> 6 </rollingPolicy> 7 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 8 <!-- LevelFilter: 级别过滤器,根据日志级别进行过滤 --> 9 <level>INFO</level> 10 <onMatch>ACCEPT</onMatch> 11 <onMismatch>DENY</onMismatch> 12 </filter> 13 <encoder> 14 <pattern>%-4relative [creatTime:%d{yyyy-MM-dd HH:mm:ss}] %-5level %logger{35} ^@^ %msg%n</pattern> 15 </encoder> 16 </appender>