반응형
Notice
Recent Posts
Recent Comments
«   2024/11   »
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
Archives
Today
Total
관리 메뉴

차근차근

egov 정부프레임워크 mariaDB MyBatis 로그 출력(log4j2) 본문

개발

egov 정부프레임워크 mariaDB MyBatis 로그 출력(log4j2)

철산92 2019. 9. 30. 23:09
반응형

pom.xml

1
2
3
4
5
6
7
8
9
10
11
<!-- mybatis log4jdbc-log4j2 라이브러리 -->
        <dependency>
            <groupId>org.bgee.log4jdbc-log4j2</groupId>
            <artifactId>log4jdbc-log4j2-jdbc4</artifactId>
            <version>1.16</version>
        </dependency>
        <dependency>
            <groupId>net.sf</groupId>
            <artifactId>log4jdbc3</artifactId>
            <version>1.1</version>
        </dependency>

log4j2 라이브러리 추가

 

 

DataBase.DriverClassName=org.mariadb.jdbc.Driver
=>DataBase.DriverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy

DataBase.Url=jdbc:mariadb://localhost:3306/utilMakeDB 
=>DataBase.Url=jdbc:log4jdbc:mariadb://localhost:3306/utilMakeDB

 

context-datasource.xml 파일에 DB설정을 위에 값으로 변경한다.

 

 

log4jdbc.log4j2.properties 파일생성 

log4jdbc.drivers=org.mariadb.jdbc.Driver
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0

파일안 내용을 입력

 

logback.xml 파일생성 

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <!-- log4jdbc-log4j2 -->
    <logger name="jdbc.sqlonly" level="DEBUG"/>
    <logger name="jdbc.sqltiming" level="INFO"/>
    <logger name="jdbc.audit" level="WARN"/>
    <logger name="jdbc.resultset" level="ERROR"/>
    <logger name="jdbc.resultsettable" level="ERROR"/>
    <logger name="jdbc.connection" level="INFO"/>
</configuration>

s

파일안 내용을 입력

 

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
<?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>
        <!-- 로그파일 생성을 위한 Appender -->
        <RollingFile name="dailyRollingFileAppender" fileName="d:/tdms_logs/tdms.log" filePattern="d:/tdms_logs/tdms_%d{yyyy-MM-dd}.log" append="true">
        <PatternLayout pattern="%d %5p [%c] %m%n" />
        <Policies>
        <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
        </Policies>
    </RollingFile>
    </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>

 

 

결과화면

 

참조 : https://www.leafcats.com/45

반응형
Comments