Skip to content

Commit

Permalink
feat: LogBack 롤링 정책 수정, 로그 레벨에 따른 분리 (#332)
Browse files Browse the repository at this point in the history
* feat: Logback 로그 레벨 분리

* feat: Lockback 로그 레벨 분리

---------

Co-authored-by: Arachneee <[email protected]>
  • Loading branch information
3Juhwan and Arachneee authored Aug 13, 2024
1 parent be83b89 commit 901c25a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 21 deletions.
12 changes: 0 additions & 12 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ management:
exposure:
include: health, metrics, logfile

logging:
level:
root: debug
org.springframework.web: debug
server.haengdong: debug

file:
name: logs/spring-boot-application.log
path: logs
config: classpath:logback-spring.xml

server:
servlet:
encoding:
Expand All @@ -75,4 +64,3 @@ spring:
import: classpath:config/application-dev.yml
activate:
on-profile: dev

2 changes: 1 addition & 1 deletion server/src/main/resources/config
88 changes: 80 additions & 8 deletions server/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,71 @@
<configuration>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/spring-boot-application.log</file>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- 콘솔에 로그 출력 형식 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="ERROR-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<file>logs/spring-boot-application-error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/spring-boot-application-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<!-- 날짜, 시간, 로그 레벨, 스레드 이름, 로거 이름, 메시지 형식 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="WARN-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<file>logs/spring-boot-application-warn.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/spring-boot-application-warn.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<!-- 날짜, 시간, 로그 레벨, 스레드 이름, 로거 이름, 메시지 형식 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="INFO-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<file>logs/spring-boot-application-info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/spring-boot-application-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<!-- 날짜, 시간, 로그 레벨, 스레드 이름, 로거 이름, 메시지 형식 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="DEBUG-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<file>logs/spring-boot-application-debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/spring-boot-application.%d{yyyy-MM-dd}.log</fileNamePattern>
<fileNamePattern>logs/spring-boot-application-debug.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
Expand All @@ -11,10 +74,19 @@
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="ROLLING"/>
</root>
<springProfile name="default">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>

<logger name="org.springframework.web" level="DEBUG"/>
<logger name="server.haengdong" level="DEBUG"/>
<springProfile name="default">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ERROR-ROLLING"/>
<appender-ref ref="WARN-ROLLING"/>
<appender-ref ref="INFO-ROLLING"/>
<appender-ref ref="DEBUG-ROLLING"/>
</root>
</springProfile>
</configuration>

0 comments on commit 901c25a

Please sign in to comment.