2017년 6월 22일 목요일

spring log4j2 설정

1. pom.xml 추가

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

2. dataSource 수정


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"/>
    <property name="url" value="jdbc:log4jdbc:mysql:thin:@123.456.789.12:1521:test" />
    <property name="username" value="test"/>
    <property name="password" value="123"/>
</bean>

3. log4j2.xml 수정


<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <!-- Console 출력을 위한 Appender -->
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %5p [%c] %m%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="java.sql" level="INFO" additivity="false">
            <AppenderRef ref="console" />
            <AppenderRef ref="dailyRollingFileAppender" />
        </Logger>
        <Logger name="egovframework" level="DEBUG" additivity="false">
            <AppenderRef ref="console" />
            <AppenderRef ref="dailyRollingFileAppender" />
        </Logger>
  <!-- log SQL with timing information, post execution -->
        <Logger name="jdbc.sqltiming" level="INFO" additivity="false">
            <AppenderRef ref="console" />
            <AppenderRef ref="dailyRollingFileAppender" />
        </Logger>
        <Logger name="org.springframework" level="INFO" additivity="false">
            <AppenderRef ref="console" />
            <AppenderRef ref="dailyRollingFileAppender" />
        </Logger>
        <Root level="INFO">
            <AppenderRef ref="console" />
            <AppenderRef ref="dailyRollingFileAppender" />
        </Root>
    </Loggers>
</Configuration>
Share:

0 개의 댓글:

댓글 쓰기