logback batch and the great log file

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

<appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender">

    <file>E:/logs/mylog.txt</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

      <!-- rollover daily -->

      <fileNamePattern>E:/logs/mylog-%d{yyyy-MM-dd_HH-mm}.%i.log</fileNamePattern>

      <maxHistory>5</maxHistory>

      <timeBasedFileNamingAndTriggeringPolicy

            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">

        <!-- or whenever the file size reaches 100MB -->

        <maxFileSize>100MB</maxFileSize>

      </timeBasedFileNamingAndTriggeringPolicy>

    </rollingPolicy>

    <encoder>

      <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n</pattern>

       <charset class="java.nio.charset.Charset">UTF-8</charset>

    </encoder>

</appender>


  <logger name="javax.validation" level="info" />

<logger name="com.lppz.takeout.daq" level="info" />

<logger name="org.springframework.beans.factory" level="warn"/>

<logger name="org.springframework.transaction" level="info" />

<logger name="org.springframework.validation" level="info" />

<logger name="org.springframework.test" level="warn" />

<logger name="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" level="trace" appender-ref="logfile"/>

    <root level="info">

<appender-ref ref="logfile"/>

    </root>

</configuration>

On the above analysis:

ch.qos.logback.core.rolling.RollingFileAppender log output class files used, its basic properties include <file> specifies the input file path, designated Encoder log format.

Wherein, rollingPolicy tag specifies the sub-log strategy, ch.qos.logback.core.rolling.TimeBasedRollingPolicy sub-class implementation strategy is based on time interval is a sub event fileNamePattern minimum unit specified in accordance with, such as the example the% d {yyyy-mM-dd_HH-mm} is the smallest unit of sub-events, it is the trigger for 1 minute each time triggered policy add new content to the log, if the condition is satisfied, it will copy mylog.txt to E: / logs / directory and renamed mylog-2010-06-22_13-13.1.log, and delete the original mylog.txt.

maxHistory value specified E: / logs directory. The maximum number of similar mylog-2010-06-22_13-13.1.log file, when more than deletes the oldest files.

Additionally, policy may also be nested within each other, such as in the present embodiment time policy file size is nested strategy, ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP determined to achieve single file size specified in significantly when it exceeds maxFileSize when hours, the filename variable% i increments by one, i.e., the time to trigger is not satisfied and the size satisfies the trigger, and generates mylog-2010-06-22_13-13.1.log mylog-2010-06-22_13-13.2.log two files.

Guess you like

Origin blog.csdn.net/weixin_33681778/article/details/90970901