Small class D - Basics zero SpringBoot2.X to combat _ Section 11 Logback logging framework and introduce SpringBoot integrated combat _45, SpringBoot2.x log to explain the actual configuration and Logback

notes

2, SpringBoot2.x log to explain the configuration and custom Logback combat
    Introduction: explain SpringBoot2.x integration Logback actual configuration

        1, official website: https: //docs.spring.io/spring-boot/docs/2.1.0.BUILD- SNAPSHOT / reference / htmlsingle / # boot -features-logging

           various components case: HTTPS: //logback.qos.ch/manual/index.html
        
        2, start the log analysis SpringBoot
            1) By default, Spring boot log output to the control Taiwan

        3, the integration of real logback
            1) create a log file logback-spring.xml, the official recommended -spring.xml end
                loaded by default load the configuration order logback-spring.xml, logback-spring.groovy, logback.xml, or logback.groovy
            
            comments : <Configuration>
                child node
                <the appender> </ the appender>                       
                <Logger> </ Logger>
                <Root> </ root> (to be added at the end)        

 

Start


The default start springboot of which contains a logback







the Spring activated when the default is Info level


want to get more information with the java-jar will add --dubug behind

the new, logback-spring.xml documents



prepared in advance log files copied

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

     <appender name="consoleApp" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>
                %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n
            </pattern>
        </layout>
    </appender>

    <appender name="fileInfoApp" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
             <level>ERROR</level>
            <onMatch>DENY</onMatch>
            <onMismatch>ACCEPT</onMismatch>
        </filter>
        <encoder>
            <pattern>
                %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n
            </pattern>
        </encoder>
        <!-- 滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 路径 -->
            <fileNamePattern>app_log/log/app.info.%d.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="fileErrorApp" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <encoder>
            <pattern>
                %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n
            </pattern>
        </encoder>
        
        <!-- 设置滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 路径 -->
            <fileNamePattern>app_log/log/app.err.%d.log</fileNamePattern>
            
            <! - control the maximum number of reserved archive, delete old files exceeds the number is assumed that the scrolling of each month, 
            and <maxHistory> 1, save only the last month of files, old files before deletion - -> 
             < MaxHistory > . 1 </ MaxHistory > 
            
        </ rollingPolicy > 
    </ the appender > 
   < the root Level = "the INFO" >   
        < the appender-REF REF = "ConsoleApp" /> 
        < the appender-REF REF = "fileInfoApp" /> 
        < the appender -REF REF = "fileErrorApp" /> 
    </ the root >
</configuration>

 





Various components Case: https: //logback.qos.ch/manual/index.html


Test log


The package is introduced org.slf4j.Logger

test several levels of log output

launcher







root node is loaded rearmost





file info inside info and output both levels log warn.

This is because the configuration of the filter here

if the change root here debug

restart the application



error or error only

filters out error level, so debug, warn, info are output to the file inside these levels


degbu there are too many levels of useless information would be interference. Here general use Info level will not generate too much logging information, we take up disk space




 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11431341.html
Recommended