SpringFramework

Spring Legacy Mybatis Execute Query 콘솔출력

유혁스쿨 2024. 2. 18. 23:50
728x90
반응형

 

Maven Dependency를 추가한다.

[ log4j2-jdbc4.1 ]을 추가한다.

		<dependency>
			<groupId>org.bgee.log4jdbc-log4j2</groupId>
			<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
			<version>1.16</version>
		</dependency>

 

[ log4jdbc.log4j2.properties ] 파일 추가

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0

 

 

 

JDBC Driver 설정에 대한 Properties 파일을 아래와 같이 변경한다.

/* [오라클] */

// 변경 이전 값
oracle.driver=oracle.jdbc.driver.OracleDriver
oracle.url=jdbc:oracle:thin:@54.180.135.210:1521:xe

// 변경할 값
oracle.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
oracle.url=jdbc:log4jdbc:oracle:thin:@54.180.135.210:1521:xe

/* [mySQL] */

// 변경 이전 값
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/스키마명?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul

// 변경할 값
driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url=jdbc:log4jdbc:mysql://localhost:3306/스키마명?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul

 

[ log4j.xml ]를 아래와 같이 수정한다.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="console" class="org.apache.log4j.ConsoleAppender">
       <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d %5p [%c] %m%n" />
       </layout>
    </appender>
    
    <appender name="console-sql" class="org.apache.log4j.ConsoleAppender">
       <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d %5p %c %m%n" />
       </layout>
    </appender>

    <logger name="jdbc.sqltiming" additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="console-sql" />
    </logger>

    <logger name="jdbc.resultsettable" additivity="false">
        <level value="INFO" />
        <appender-ref ref="console" />
    </logger>

</log4j:configuration>

 

728x90
반응형