Post

Spring Boot Log4jdbc 설정

1. Log4jdbc Download

  • Maven
1
2
3
4
5
<dependency>
    <groupId>org.bgee.log4jdbc-log4j2</groupId>
    <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
    <version>1.16</version>
</dependency>

2. 설정

1) log4jdbc.log4j2.properties

  • 경로: src/main/resources/log4jdbc.log4j2.properties
1
2
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0

2) application.properties

  • 경로: src/main/resources/application.properties
1
2
3
4
spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.jdbc-url=jdbc:log4jdbc:postgresql://localhost:5432/postgres?charSet=UTF-8
spring.datasource.username=postgres
spring.datasource.password=password

3. 적용

1) logback.xml 추가

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="true">
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <charset>UTF-8</charset>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="jdbc" level="off"/>
    <logger name="jdbc.sqlonly" level="off"/>
    <logger name="jdbc.sqltiming" level="debug"/>
    <logger name="jdbc.audit" level="off"/>
    <logger name="jdbc.resultset" level="off"/>
    <logger name="jdbc.resultsettable" level="debug"/>
    <logger name="jdbc.connection" level="off"/>

    <root level="info">
        <appender-ref ref="CONSOLE" />
    </root>
</configuration>

4. 결과

img001

[출처 및 참고]

This post is licensed under CC BY 4.0 by the author.