pom.xml에 dependency를 추가한다.
<dependency>
<groupId>org.lazyluke</groupId>
<artifactId>log4jdbc-remix</artifactId>
<version>0.2.7</version>
</dependency>
java resoures / src/main/resources 에서 context-datasource.xml 파일을 엽니다.
// 기존의 context-datasource.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd">
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/comp/env/jdbc/(해당주소) " />
<property name="resourceRef" value="true" />
</bean>
</beans>
==>다음과 같이 수정합니다
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd">
<bean id="dataSourceSpied" class="org.springframework.jndi.JndiObjectFactoryBean"> <!--id를 변경합니다. -->
<property name="jndiName" value="java:/comp/env/jdbc/(해당주소)" />
</bean>
<!--추가된 부분-->
<bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource">
<constructor-arg ref="dataSourceSpied" />
<property name="logFormatter">
<bean class="net.sf.log4jdbc.tools.Log4JdbcCustomFormatter">
<property name="loggingType" value="MULTI_LINE" />
<property name="sqlPrefix" value="SQL : "/>
</bean>
</property>
</bean>
<!-- -->
</beans>
log4j2.xml 을 엽니다.
<!--기존 파일 -->
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %5p [%c] %m%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="java.sql" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<Logger name="egovframework" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- log SQL with timing information, post execution -->
<Logger name="jdbc.sqltiming" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<Logger name="org.springframework" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<Root level="DEBUG">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
==> <!-- 다음과 같이 수정합니다-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<Configuration>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %5p [%c] %m%n" />
</Console>
<!--추가된 부분-->
<Console name="console-infolog" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p %m%n" />
</layout>
</Console>
<!-- -->
</Appenders>
<Loggers>
<Logger name="java.sql" level="info" additivity="false">
<AppenderRef ref="console" />
</Logger>
<Logger name="egovframework" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- log SQL with timing information, post execution -->
<Logger name="jdbc.sqltiming" level="info" additivity="false">
<AppenderRef ref="console" />
</Logger>
<Logger name="org.springframework" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- 추가된 부분-->
<!-- Query Loggers -->
<Logger name="jdbc.sqlonly" additivity="false">
<level value="INFO"/>
<appender-ref ref="console-infolog"/>
</Logger>
<!-- -->
<Root level="DEBUG">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
출처 : http://addio3305.tistory.com/66
출처 : https://goodmysky.tistory.com/7
'백엔드 개발 놀이터 > Mybatis' 카테고리의 다른 글
[Mybatis] 동적 쿼리 (가변 컬럼명) (0) | 2020.04.10 |
---|---|
Mybatis #과 $의 차이 (0) | 2020.04.06 |
[MyBatis] 동적SQL 처리하기 : ForEach (0) | 2020.04.02 |