Mybatis 쿼리 로그 출력

프로그래밍|2016. 3. 2. 17:58

쿼리 검수를 위해 mybatis 플러그인에 아래 interceptor를 추가

 - 바인딩 변수에 값이 맵핑되어 있는 쿼리문 출력가능





[SQL Map Config]

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

<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

        <settings>

               <setting name="cacheEnabled" value="false" />

               <setting name="useGeneratedKeys" value="true" />

               <setting name="defaultExecutorType" value="REUSE" />

        </settings>

       

        <plugins>

            <plugin interceptor="com.test.common.mybatis.MybatisSqlLogInterceptor"/>

        </plugins>

       

</configuration>



[Logback Config]

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

        <File>/home/test/${SERVER_NAME}/tomcat/logs/sql/mybatis_sql.log</File>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

            <fileNamePattern>/home/test/${SERVER_NAME}/tomcat/logs/sql/mybatis_sql.%d{yyyy-MM-dd}.log.gz</fileNamePattern>

            <maxHistory>60</maxHistory>

        </rollingPolicy>

        <encoder>

            <Pattern>%m%n</Pattern>

        </encoder>

    </appender>

 

 

<logger name="MYBATIS_SQL_LOG" level="info" additivity="false">

               <appender-ref ref="MYBATIS_SQL_LOG_FILE" />

        </logger>


댓글()