Skip to content

Commit

Permalink
feat: โœจ Log System Implementation (#221)
Browse files Browse the repository at this point in the history
* chore: ignore log directory

* feat: logging xml

* chore: add log property in the external-api-module

* chore: external-api logging setting

* chore: external-api logback-spring.xml

* fix: external-api log total-size-cap to 10mb

* chore: add file max capacity

* chore: ignore logs directory

* chore: socket log config setting

* chore: socket server logback setting
  • Loading branch information
psychology50 authored Jan 15, 2025
1 parent dd54569 commit 0c3a98f
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pennyway-app-external-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ bin/
.DS_Store

## Test API
src/main/java/kr/co/pennyway/api/apis/test
src/main/java/kr/co/pennyway/api/apis/test

## Log Files
**/logs
11 changes: 11 additions & 0 deletions pennyway-app-external-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ springdoc:
groups:
enabled: true

log:
config:
filename: app-local

---
spring:
config:
Expand All @@ -53,6 +57,13 @@ springdoc:
groups:
enabled: true

log:
config:
filename: app-dev
maxHistory: 7
maxFileSize: 10MB
totalSizeCap: 500MB

---
spring:
config:
Expand Down
80 changes: 80 additions & 0 deletions pennyway-app-external-api/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- ํ”„๋กœํŒŒ์ผ๋ณ„ ์„ค์ • ํŒŒ์ผ ๋กœ๋“œ -->
<springProfile name="local,dev,prod">
<property resource="application.yml"/>
</springProfile>

<!-- ๋กœ๊ทธ ์„ค์ • ํ”„๋กœํผํ‹ฐ -->
<property name="LOG_PATH" value="./pennyway-app-external-api/src/main/resources/logs"/>
<springProperty name="LOG_FILE_NAME" source="log.config.filename"/>
<springProperty name="LOG_MAX_FILE_SIZE" source="log.config.maxFileSize"/>
<springProperty name="LOG_MAX_HISTORY" source="log.config.maxHistory"/>
<springProperty name="LOG_TOTAL_SIZE_CAP" source="log.config.totalSizeCap"/>

<!-- ๋กœ๊ทธ ํŒจํ„ด์— ์ƒ‰์ƒ ์ ์šฉ -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>

<!-- ๋กœ๊ทธ ํŒจํ„ด ์„ค์ • -->
<property name="CONSOLE_LOG_PATTERN"
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] %clr(%-5level) %clr(${PID:-}){magenta} %clr(---){faint} %clr([%15.15thread]){faint} %clr(%-40.40logger{36}){cyan} %clr(:){faint} %msg%n"/>
<property name="FILE_LOG_PATTERN"
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] %-5level ${PID:-} --- [%15.15thread] %-40.40logger{36} : %msg%n"/>

<!-- ์ฝ˜์†” ์ถœ๋ ฅ ์„ค์ • -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
</layout>
</appender>

<!-- ํŒŒ์ผ ์ถœ๋ ฅ ์„ค์ • -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <file>${LOG_PATH}/${LOG_FILE_NAME}.log</file>-->
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>

<!-- ์—๋Ÿฌ ๋ฐœ์ƒ์‹œ ๋ฌด์‹œํ•˜๋„๋ก ์„ค์ • -->
<prudent>true</prudent>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- ๋กค๋ง๋œ ํŒŒ์ผ ๋ช…๋ช… ๊ทœ์น™ -->
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/${LOG_FILE_NAME}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- ํŒŒ์ผ๋‹น ์ตœ๋Œ€ ํฌ๊ธฐ -->
<maxFileSize>${LOG_MAX_FILE_SIZE}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- ๋ณด๊ด€ ์ฃผ๊ธฐ -->
<maxHistory>${LOG_MAX_HISTORY}</maxHistory>
<!-- ์ด ํŒŒ์ผ ํฌ๊ธฐ ์ œํ•œ -->
<totalSizeCap>${LOG_TOTAL_SIZE_CAP}</totalSizeCap>
</rollingPolicy>
</appender>

<!-- ํ”„๋กœํŒŒ์ผ๋ณ„ ๋กœ๊ทธ ์„ค์ • -->
<springProfile name="local">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>

<springProfile name="dev">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>

<logger name="org.springframework.web" level="debug" additivity="false">
<appender-ref ref="FILE"/>
</logger>
</springProfile>

<springProfile name="prod">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
<logger name="org.springframework.web" level="debug" additivity="false">
<appender-ref ref="FILE"/>
</logger>
</springProfile>
</configuration>
5 changes: 4 additions & 1 deletion pennyway-socket/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ bin/

### Test ###
src/main/resources/compose.yml
src/main/resources/static/
src/main/resources/static/

## Log files ##
**/logs
11 changes: 11 additions & 0 deletions pennyway-socket/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,23 @@ spring:
activate:
on-profile: local

log:
config:
filename: socket-local

---
spring:
config:
activate:
on-profile: dev

log:
config:
filename: socket-dev
maxHistory: 7
maxFileSize: 10MB
totalSizeCap: 500MB

---
spring:
config:
Expand Down
90 changes: 90 additions & 0 deletions pennyway-socket/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- ํ”„๋กœํŒŒ์ผ๋ณ„ ์„ค์ • ํŒŒ์ผ ๋กœ๋“œ -->
<springProfile name="local,dev,prod">
<property resource="application.yml"/>
</springProfile>

<!-- ๋กœ๊ทธ ์„ค์ • ํ”„๋กœํผํ‹ฐ -->
<property name="LOG_PATH" value="./pennyway-socket/src/main/resources/logs"/>
<springProperty name="LOG_FILE_NAME" source="log.config.filename"/>
<springProperty name="LOG_MAX_FILE_SIZE" source="log.config.maxFileSize"/>
<springProperty name="LOG_MAX_HISTORY" source="log.config.maxHistory"/>
<springProperty name="LOG_TOTAL_SIZE_CAP" source="log.config.totalSizeCap"/>

<!-- ๋กœ๊ทธ ํŒจํ„ด์— ์ƒ‰์ƒ ์ ์šฉ -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>

<!-- WebSocket ์„œ๋ฒ„์šฉ ๋กœ๊ทธ ํŒจํ„ด ์„ค์ • - ์„ธ์…˜ ID์™€ ์—ฐ๊ฒฐ ์ƒํƒœ ์ •๋ณด ํฌํ•จ -->
<property name="CONSOLE_LOG_PATTERN"
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] %clr(%-5level) %clr(${PID:-}){magenta} %clr(---){faint} %clr([%15.15thread]){faint} %clr(%-40.40logger{36}){cyan} %clr(:){faint} %msg%n"/>
<property name="FILE_LOG_PATTERN"
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative] %-5level ${PID:-} --- [%15.15thread] %-40.40logger{36} : %msg%n"/>

<!-- ์ฝ˜์†” ์ถœ๋ ฅ ์„ค์ • -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
</layout>
</appender>

<!-- ํŒŒ์ผ ์ถœ๋ ฅ ์„ค์ • -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>

<!-- ์—๋Ÿฌ ๋ฐœ์ƒ์‹œ ๋ฌด์‹œํ•˜๋„๋ก ์„ค์ • -->
<prudent>true</prudent>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- ๋กค๋ง๋œ ํŒŒ์ผ ๋ช…๋ช… ๊ทœ์น™ -->
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}/${LOG_FILE_NAME}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- ํŒŒ์ผ๋‹น ์ตœ๋Œ€ ํฌ๊ธฐ -->
<maxFileSize>${LOG_MAX_FILE_SIZE}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- ๋ณด๊ด€ ์ฃผ๊ธฐ -->
<maxHistory>${LOG_MAX_HISTORY}</maxHistory>
<!-- ์ด ํŒŒ์ผ ํฌ๊ธฐ ์ œํ•œ -->
<totalSizeCap>${LOG_TOTAL_SIZE_CAP}</totalSizeCap>
</rollingPolicy>
</appender>

<!-- ํ”„๋กœํŒŒ์ผ๋ณ„ ๋กœ๊ทธ ์„ค์ • -->
<springProfile name="local">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>

<springProfile name="dev">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>

<!-- WebSocket ๊ด€๋ จ ๋กœ๊ฑฐ ์„ค์ • -->
<logger name="org.springframework.web.socket" level="debug" additivity="false">
<appender-ref ref="FILE"/>
</logger>

<logger name="org.springframework.messaging" level="debug" additivity="false">
<appender-ref ref="FILE"/>
</logger>
</springProfile>

<springProfile name="prod">
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>

<!-- WebSocket ๊ด€๋ จ ๋กœ๊ฑฐ ์„ค์ • -->
<logger name="org.springframework.web.socket" level="debug" additivity="false">
<appender-ref ref="FILE"/>
</logger>

<logger name="org.springframework.messaging" level="debug" additivity="false">
<appender-ref ref="FILE"/>
</logger>
</springProfile>
</configuration>

0 comments on commit 0c3a98f

Please sign in to comment.