pom.xml에 dependency를 추가한다.
1 2 3 4 5 | <dependency> <groupId>org.lazyluke</groupId> <artifactId>log4jdbc-remix</artifactId> <version>0.2.7</version> </dependency> | cs |
java resoures / src/main/resources 에서 context-datasource.xml 파일을 엽니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // 기존의 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 을 엽니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | <!--기존 파일 --> <?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> | cs |
'java' 카테고리의 다른 글
[java] 중복로그인 처리 (0) | 2017.04.25 |
---|---|
화면인쇄페이지 (0) | 2016.10.19 |