how to configure logback for Mybatis to print my SQL

前端 未结 3 1417
有刺的猬
有刺的猬 2020-12-13 05:32


    
        <         


        
相关标签:
3条回答
  • 2020-12-13 05:45
         <logger name="org.mybatis">
          <level value="TRACE"/>
      </logger>
    
    <logger name="java.sql">
        <level value="WARN"/>
    </logger> 
    

    I used the above code snippet in my logback.xml and got the sql query in logger. If require to print sql in specific logger, use tag.

    0 讨论(0)
  • 2020-12-13 05:49

    thanks, I add to logback.xml

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logFile}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${logFile}.%d.zip</fileNamePattern>
            <maxHistory>5</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>[%date] [%level] %msg [%file:%line] [%logger{100}] [%thread] [AspLink-${project.version}]%n</pattern>
        </encoder>
    </appender>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[AspLink-${project.version}] [%level] %msg [%file:%line] [%logger{100}]%n</pattern>
        </encoder>
    </appender>
    
    <logger name="liquibase" level="INFO" />
    <logger name="ru.company.asplink.dao" level="DEBUG" />
    <logger name="org.mybatis">
        <level value="TRACE"/>
    </logger>
    
    <root level="INFO">
        <appender-ref ref="FILE" />
        <appender-ref ref="STDOUT" />
    </root>
    

    0 讨论(0)
  • 2020-12-13 05:55

    You configuration of appender is correct but logger configuration is not.

    To log SQL statements for particular mybatis mapper set DEBUG (TRACE to see query parameters and results) level for logger with fully qualified mapper name

    <logger name="com.mycompany.myapp.mapper.MyMapper" level="DEBUG"/>
    

    You can log all SQL statements from all mappers if they are in the same package like this

    <logger name="com.mycompany.myapp.mapper" level="DEBUG"/>
    
    0 讨论(0)
提交回复
热议问题