spring boot logback no sense Configuration


spring boot1.5.x version of the log configuration has been a problem that can not be dynamic and easy configuration directly from the log file size yml profile.

    How to deal with it? Src directly in engineering springboot maven project up / down main / resources directory by adding the following logback-spring.xml file, logback-spring configuration file named logback loaded in the spring boot is the highest priority, so move along with the project you can load into force.

    Which I added to control the size of the variables in the configuration file. Specific configuration file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="60 seconds">
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/> 
    <include resource="org/springframework/boot/logging/logback/console-appender.xml"/> 
    <contextName>logback</contextName>

    <springProperty scope="logback" name="LOG_LEVEL" source="logging.logLevel" defaultValue="info" />

    <springProperty scope="logback" name="APP_NAME" source="spring.application.name" defaultValue="" />

    <springProperty scope="logback" name="PATTERN_FILE" source="logging.pattern.file" defaultValue="%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}" />

    <springProperty scope="logback" name="MAX_FILESIZE" source="logging.maxfilesize" defaultValue="100MB" />

    <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/${APP_NAME}.log}"/>

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


        <file>${LOG_FILE}</file>

        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>
                ${PATTERN_FILE}
            </pattern>
        </layout>
        

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${LOG_FILE}.%i</fileNamePattern>
            <!-- <maxHistory>${maxhistory}</maxHistory> -->
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
        </triggeringPolicy>

    </appender>

    <root level="${LOG_LEVEL}">
        <appender-ref ref="FILE" />
        <appender-ref ref="CONSOLE" />
    </root>
</configuration>

 While also yml file added to the corresponding configuration label

logging: 
  file: ../logs/aaaaa.log
  maxfilesize: 100MB
  logLevel: info

maxfilesize custom labels for each log file size settings


Guess you like

Origin www.cnblogs.com/zhyg/p/11576419.html