springboot之logback日志配置和MybatisSql打印

1.首先要配置sql打印的话,在yml文件或者application.properties文件中设置开启日志比如我的文件配置

logging:
   level:
    com:
       example:
         girl:
           mapper: debug

2.其次在logback.xml中配置如下:

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

<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    
    <property name="log_dir" value="logs/logback"/>
    
    
    <property name="maxHistory" value="30"/>

    
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger -%msg%npattern>
        encoder>
    appender>

    
    
    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERRORlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
        
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/error-log.logfileNamePattern>
            
            <maxHistory>${maxHistory}maxHistory>
        rollingPolicy>

        
        

        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%npattern>
        encoder>
    appender>


    
    <appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARNlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/warn-log.log
            fileNamePattern>
            
            <maxHistory>${maxHistory}maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%npattern>
        encoder>
    appender>


    
    <appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFOlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/info-log.log
            fileNamePattern>
            
            <maxHistory>${maxHistory}maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%npattern>
        encoder>
    appender>


    
    <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUGlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/debug-log.log
            fileNamePattern>
            
            <maxHistory>${maxHistory}maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%npattern>
        encoder>
    appender>


    
    <appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>TRACElevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/trace-log.log
            fileNamePattern>
            
            <maxHistory>${maxHistory}maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%npattern>
        encoder>
    appender>
    
    
        
                
            
            
            
            
        
    

    
    
    
    
    <root level="INFO">
        
        
        
        
        
        
        
        <appender-ref ref="DEBUG" />
        <appender-ref ref="TRACE" />
    root>
configuration>
这样就可以根据对应的级别输出到不同的文件中啦!


你可能感兴趣的:(springboot,日志配置)