์ƒˆ์†Œ์‹

๐Ÿ“ŒDevelop/โš’Config

[logback] ๋‚ด๊ฐ€์“ฐ๋Š” Spring logback ์„ค์ •

  • -

 

 

 

 

Spring logback

๊ฐœ์ธ์ ์œผ๋กœ ์“ฐ๋‹ค๊ฐ€ ํŒ€ ํ”„๋กœ์ ํŠธ๊นŒ์ง€ ํ™•์žฅํ•ด์„œ ์‚ฌ์šฉ ์ค‘์ธ logback ์„ค์ •๋“ค์„ ์ž์ฃผ ๋ฌผ์–ด๋ด์„œ ๊ธฐ๋ก์„ ๋‚จ๊ธด๋‹ค.

๋ฌผ๋ก  ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•œ ๋ถ€๋ถ„์€ ๋“ค์–ด๋‚ด๊ณ ..

 

ํ”„๋กœ์ ํŠธ์— ๊ด€๋ จ๋œ ์„ค์ •์„ ๋‹ด์€ application.properties ์— ์„ค์ • ํ›„, logback-spring.xml ์—์„œ ์ƒ์†๋ฐ›์•„ ์‚ฌ์šฉํ•˜๋„๋ก ํ–ˆ๋‹ค.

 

pom.xml

<!-- lombok -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>
<!-- log4jdbc -->
<dependency>
    <groupId>org.bgee.log4jdbc-log4j2</groupId>
    <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
    <version>1.16</version>
</dependency>

 

application.properties ํŒŒ์ผ

#Logging
logging.root.level=INFO
logging.file.path=/app/services/logs/

logback-spring.xml ํŒŒ์ผ

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- ์ค‘๊ฐ„ ๋ณ€๋™ ์‚ฌํ•ญ์„ ๋Œ€๋น„ํ•ด, application.properties ์—์„œ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๋„๋ก ๋ณ€๊ฒฝ -->
    <property resource="application.properties"/>
    <!-- LOG_ROOT_LEVEL ์˜ ๊ธฐ๋ณธ๊ฐ’์€ INFO -->
    <property name="LOG_ROOT_LEVEL" value="${logging.root.level}"/>
    <!-- LOG_ROOT_PATH ์˜ ๊ธฐ๋ณธ ๊ณ ์ •๊ฐ’์€ -->
    <property name="LOG_FILE_PATH" value="${logging.file.path}"/>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>[%d{HH:mm:ss}] [%-5level] [%M\(%L\)] - %msg%n</Pattern>
        </layout>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_FILE_PATH}/${project.name}.log</file>
        <encoder>
            <Pattern>[%d{HH:mm:ss}] [%-5level] [%M\(%L\)] - %msg%n</Pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_FILE_PATH}/${project.name}-%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>31</maxHistory>
        </rollingPolicy>
    </appender>
    <logger name="jdbc" level="ERROR" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="jdbc.sqlonly" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="jdbc.sqltiming" level="OFF" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="jdbc.audit" level="OFF" appender-ref="CONSOLE FILE" additivity="false"></logger>
    <logger name="jdbc.resultset" level="OFF" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="jdbc.resultsettable" level="OFF" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="jdbc.connection" level="OFF" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <root level="${LOG_ROOT_LEVEL}">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
    <logger name="kr.co.ooweat" level="${LOG_ROOT_LEVEL}" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE" />
    </logger>
</configuration>

 

 

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.