Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save naffan2014/06cbb4b7573759617242cdf43e1ef898 to your computer and use it in GitHub Desktop.
Save naffan2014/06cbb4b7573759617242cdf43e1ef898 to your computer and use it in GitHub Desktop.

mybatis搭载了logback日志系统。mybatis有几个文件夹分别是dao,mapper,domain。想要看sql需要查看dao。 需要通过配置logback就可以实现sql的打印。

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

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>



    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] [$logId] [$remoteAddress] [%c{0}][%M][%L][%t] %m%n</pattern>
            <charset class="java.nio.charset.Charset">UTF-8</charset>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
    </appender>

    <appender name="FILE"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logging.path}/migrate.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${logging.path}/migrate.%d{yyyy-MM-dd}.log
            </fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!--<logger name="org.springframework" level="INFO"/>-->
    <!--<logger name="org.apache.http" level="INFO"/>-->
    <!--<logger name="org.apache.shiro" level="INFO"/>-->
    <!--<logger name="org.hibernate.validator" level="INFO"/>-->
    <!--<logger name="org.apache.commons.beanutils" level="INFO"/>-->
    <!--<logger name="org.mybatis.spring.SqlSessionUtils" level="INFO"/>-->
    <!--myibatis log configure-->
    <!--<logger name="com.apache.ibatis" level="TRACE"/>-->

    <logger name="java.sql.Connection" level="DEBUG"/>
    <logger name="java.sql.Statement" level="DEBUG"/>
    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
    <logger name="java.sql.ResultSet" level="DEBUG" />
    <logger name="com.lianjia.hdic.migrate.dao.core" level="DEBUG"/>

    <logger name="io.lettuce.core.EpollProvider" level="OFF"/>
    <logger name="io.lettuce.core.KqueueProvider" level="OFF"/>

    <!--<logger name="org.mybatis" level = "TRACE" >
        <appender-ref ref="STDOUT" />
    </logger>
    <logger name="java.sql" level = "WARN" >
        <appender-ref ref="STDOUT" />
    </logger>-->
    
    <root level="INFO">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="console"/>
    </root>
</configuration>

其中,首先配置appender为console 然后,指定要查看sql的dao,也就是mapper 最后,在root中增加输出到console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment