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>