Mainly the use of AsyncAppender provide asynchronous function, and then use immediteFlush configured to use a cache (cache 8k).
Note: High version logback have pointed SizeAndTimeBasedRollingPolicy, my version is 1.0.13 can be used SizeAndTimeBasedFNATP achieved.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <substitutionProperty name="log.base" value="/home/wtposp/logs" /> </appender>--> <appender name="rollout" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Encoding>UTF-8</Encoding> <file>${log.base}/wtposp.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${log.base}/%d{yyyy-MM-dd}/wtposp-%i.log.zip</fileNamePattern> <MaxHistory>30</MaxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <!-- 设置文件大于1KB进行压缩归档 --> <maxFileSize>100MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> < Encoder > < pattern > % {DATE HH: mm: SS} [% {X-sysUUID}] -5level% C%} {0: L% -%% n-MSG </ pattern > < ImmediateFlush > to false </ ImmediateFlush > </ Encoder > </ appender > < appender name = "ASYNC" class = "ch.qos.logback.classic.AsyncAppender" > <-! is not lost log default, if 80% of the queue is full, it will. discarding TRACT, DEBUG, INFO level log -> < discardingThreshold > 0 </discardingThreshold> <!--Change the default depth of the queue, this value can affect the performance of the default value is 256 -> < QueueSize > 256 </ QueueSize > <-! Add additional the appender, only add up to a -> < the appender REF- REF = "rollOut" /> <-! <REF-REF = the appender "errorAppender" /> -> </ the appender > < the root > < Level value = "the INFO" /> < the appender REF- REF = "ASYNC" / > </ the root > </ Configuration >