-->

스프링

 

 

1. log4jdbc  라이브러리 추가

https://mvnrepository.com/artifact/org.bgee.log4jdbc-log4j2/log4jdbc-log4j2-jdbc4.1

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

 

2.  src/main/resources 위치에 다음과 같이 파일 생성

log4jdbc.log4j2.properties

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

 

 

3.  driverClassName  :net.sf.log4jdbc.sql.jdbcapi.DriverSpy

jdbcUrl 에 log4jdbc 추가

	<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
		<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
		<property name="jdbcUrl" value="jdbc:log4jdbc:mysql://localhost:3306/dbname"></property>
		<property name="username" value="username"></property>
		<property name="password" value="1234"></property>
	</bean>

 

 

 

4. 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/">

	<!-- Appenders -->
	<appender name="console" class="org.apache.log4j.ConsoleAppender">
		<param name="Target" value="System.out" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%-5p: %c - %m%n" />
		</layout>
	</appender>
	
	<!-- Application Loggers -->
	<logger name="com.itwillbs.c3t2">
		<level value="info" />
	</logger>
	
	<!-- 3rdparty Loggers -->
	<logger name="org.springframework.core">
		<level value="info" />
	</logger>
	
	<logger name="org.springframework.beans">
		<level value="info" />
	</logger>
	
	<logger name="org.springframework.context">
		<level value="info" />
	</logger>

	<logger name="org.springframework.web">
		<level value="info" />
	</logger>

	<!-- Root Logger -->
	<root>
		<priority value="info" />
		<appender-ref ref="console" />
	</root>
	
</log4j:configuration>

 

 

또는 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="egovframework" level="DEBUG" additivity="false">
            <AppenderRef ref="console" />
        </Logger>
        <Logger name="org.egovframe" level="DEBUG" additivity="false">
            <AppenderRef ref="console" />
        </Logger>
        
        <Logger name="org.springframework" level="INFO" additivity="false">
            <AppenderRef ref="console" />
        </Logger>
        
        <!--  SQL 쿼리 문장 -->
     
        <Logger name="java.sql" level="ERROR" additivity="false">
            <AppenderRef ref="console" />
        </Logger>
        
        <Logger name="jdbc.sqlonly" level="ERROR" 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="jdbc.audit" level="WARN" additivity="false">
             <appender-ref ref="console"/>
         </Logger>
        
         <Logger name="jdbc.resultset" level="WARN" additivity="false">
             <appender-ref ref="console"/>
         </Logger>
         
 
        <Logger name="jdbc.resultSettable" level="INFO" additivity="false">
            <appender-ref ref="console"/>
        </Logger>
        
 
        <Root level="INFO">
            <AppenderRef ref="console" />
        </Root>
    </Loggers>
</Configuration>

 

 

 

 

spring

 

about author

PHRASE

Level 1  라이트

댓글 ( 4)

댓글 남기기

작성