Skip to content

Commit

Permalink
Config: 로그 파일 저장 추가, 항목 추가 (#266)
Browse files Browse the repository at this point in the history
* Config: Add async file log appender for dev, prod env

* Config: Set log to show servlet, security, sql info for all profile.

* CICD: Mount log directory.

* Fix: Fix property

* Fix: Extract and set log file name and base property for all profiles.
  • Loading branch information
huGgW authored Apr 11, 2024
1 parent dff39af commit dc3c400
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
1 change: 1 addition & 0 deletions docker-compose-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
volumes:
- ./cse-files:/app/cse-files
- ./files:/app/files
- ./logs:/app/logs

environment:
SPRING_DATASOURCE_URL: "jdbc:mysql://host.docker.internal:3306/${MYSQL_DATABASE}?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true"
Expand Down
44 changes: 27 additions & 17 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spring:
hikari:
maximum-pool-size: 65
jpa:
show-sql: true
properties:
hibernate:
dialect: com.wafflestudio.csereal.common.config.MySQLDialectCustom
Expand Down Expand Up @@ -47,6 +48,19 @@ endpoint:

login-page: http://localhost:8080


logging:
level:
org:
springframework:
security: DEBUG
web:
servlet: DEBUG

customlog:
file:
name: "csereal-backend"

---
spring:
config.activate.on-profile: local
Expand All @@ -57,7 +71,6 @@ spring:
jpa:
hibernate:
ddl-auto: update
show-sql: true
open-in-view: false
security:
oauth2:
Expand All @@ -74,12 +87,9 @@ spring:
issuer-uri: https://id.snucse.org/o
jwk-set-uri: https://id.snucse.org/o/jwks

logging:
level:
# default: INFO
org:
springframework:
security: DEBUG
customlog:
file:
base: "./logs"

---
spring:
Expand Down Expand Up @@ -120,13 +130,16 @@ slack:
token: ${SLACK_TOKEN}
channel: ${SLACK_CHANNEL}

customlog:
file:
base: "/app/logs"

---
spring:
config.activate.on-profile: dev
jpa:
hibernate:
ddl-auto: update
show-sql: true
open-in-view: false
security:
oauth2:
Expand Down Expand Up @@ -156,6 +169,9 @@ endpoint:

login-page: https://${URL}

customlog:
file:
base: "./logs"
---
spring:
config.activate.on-profile: test
Expand All @@ -167,7 +183,6 @@ spring:
jpa:
database: h2
database-platform: org.hibernate.dialect.H2Dialect
show-sql: true
open-in-view: false
hibernate:
ddl-auto: create-drop
Expand All @@ -177,11 +192,6 @@ spring:
h2:
console:
enabled: true

logging:
level:
# default: INFO
org:
springframework:
security: DEBUG

customlog:
file:
base: "./logs"
29 changes: 27 additions & 2 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
<import class="com.cyfrania.logback.SlackChatApi" />


<!-- Slack Appender Config-->
<springProperty name="SLACK_TOKEN" source="slack.token" />
<springProperty name="SLACK_CHANNEL" source="slack.channel" />
<property name="SLACK_LOG_PATTERN" value="\n*================================*\n*====== Backend Server LOG ======*\n*================================*\n\n${FILE_LOG_PATTERN}\n\n*--------------------------------*\n\n" />
<!-- <property name="SLACK_LOG_CHARSET" value="${CONSOLE_LOG_CHARSET}" />-->


<appender name="SLACK" class="SlackAppender">
<sender class="SlackChatApi">
Expand All @@ -36,6 +35,30 @@
</appender>


<!-- File appender -->
<springProperty name="LOG_FILE_NAME" source="customlog.file.name" />
<springProperty name="LOG_FILE_BASE" source="customlog.file.base" />

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE_BASE}/${LOG_FILE_NAME}.log</file>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<charset>${FILE_LOG_CHARSET}</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE_BASE}/${LOG_FILE_NAME}_%d{yyyy-MM-dd}.log</fileNamePattern>
<cleanHistoryOnStart>false</cleanHistoryOnStart>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>

<appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
<maxFlushTime>5000</maxFlushTime>
</appender>



<springProfile name="local">
<root level="INFO">
<appender-ref ref="CONSOLE" />
Expand All @@ -45,13 +68,15 @@
<springProfile name="dev">
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ASYNC_FILE" />
</root>
</springProfile>

<springProfile name="prod">
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ASYNC_SLACK" />
<appender-ref ref="ASYNC_FILE" />
</root>
</springProfile>

Expand Down

0 comments on commit dc3c400

Please sign in to comment.