써먹는 웹개발

egov 전자정부프레임워크 mariadb mybatis 로그 출력 (log4j2) 본문

Server/Spring

egov 전자정부프레임워크 mariadb mybatis 로그 출력 (log4j2)

kmhan 2023. 6. 12. 18:07


728x90
반응형

※ egov 전자정부프레임워크는 log4jdbc-remix가 사용되지 않습니다.

 

1. 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>
cs

 

2. context-datasource.xml

1
2
3
4
5
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
cs

 

3. ( resources > ) log4jdbc.log4j2.properties 

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

 

4. ( resources > ) 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>
cs

 

5. ( resources > ) 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>
cs

 

차례대로 추가 및 수정

 

출처 : https://rhkdgus0779.tistory.com/53

 

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

pom.xml 1 2 3 4 5 6 7 8 9 10 11 org.bgee.log4jdbc-log4j2 log4jdbc-log4j2-jdbc4 1.16 net.sf log4jdbc3 1.1 log4j2 라이브러리 추가 DataBase.DriverClassName=org.mariadb.jdbc.Driver =>DataBase.DriverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy DataBas

rhkdgus0779.tistory.com

 

출처의 출처 : https://www.leafcats.com/45

728x90
반응형


Comments