Skip to content

Commit

Permalink
Feat: 로그 파일 저장 설정용 logback-spring.yml 추가 (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaewon-pro authored Oct 24, 2024
1 parent 3494087 commit 38b2146
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ out/
### etc ###
.DS_Store

### Project ###
**/main/generated/

**/resources/.env
**/resources/.env.*
!**/resources/.env.example

**/resources/app/apple/*.p8

### Logs ###
logs/**
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ dependencies {

implementation(libs.resilience4j.spring.boot)

implementation(libs.bundles.logback)

runtimeOnly(libs.micrometer.registry.prometheus)

testImplementation(libs.bundles.spring.boot.test)
Expand Down
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ caffeine = { group = "com.github.ben-manes.caffeine", name = "caffeine", version
micrometer-registry-prometheus = { group = "io.micrometer", name = "micrometer-registry-prometheus", version = "1.13.4" }
resilience4j-spring-boot = { group = "io.github.resilience4j", name = "resilience4j-spring-boot3", version = "2.2.0" }

logback-json-classic = { group = "ch.qos.logback.contrib", name = "logback-json-classic", version = "0.1.5" }
logback-jackson = { group = "ch.qos.logback.contrib", name = "logback-jackson", version = "0.1.5" }

[bundles]
spring-boot = [
"spring-boot-starter",
Expand Down Expand Up @@ -79,6 +82,11 @@ jooq = [
"jooq-meta",
]

logback = [
"logback-json-classic",
"logback-jackson",
]

[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }
spring-dependency-management = { id = "io.spring.dependency-management", version.ref = "dependency-management" }
Expand Down
45 changes: 45 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<configuration>
<property resource="logback-variables.properties"/>

<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>

<timestamp key="ToMonth" datePattern="yyyy-MM"/>
<timestamp key="ToDay" datePattern="yyyy-MM-dd"/>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%clr(%d{${LOG_DATEFORMAT_PATTERN}}){magenta} %clr([%thread]){blue} %clr(%-5level){} %clr([%logger{0}:%line]){cyan} : %msg %n
</pattern>
</layout>
</appender>

<appender name="FILE1" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<timestampFormat>${LOG_DATEFORMAT_PATTERN}</timestampFormat>

<timestampFormatTimezoneId>Asia/Seoul</timestampFormatTimezoneId>
<appendLineSeparator>true</appendLineSeparator>

<jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
<prettyPrint>false</prettyPrint>
</jsonFormatter>
</layout>
</encoder>

<file>${LOG_PATH}/${ToMonth}/${ToDay}_${LOG_FILE_NAME}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>
${LOG_PATH}/%d{yyyy-MM}/%d{yyyy-MM-dd}_${LOG_FILE_NAME}_%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>

<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE1"/>
</root>

</configuration>
3 changes: 3 additions & 0 deletions src/main/resources/logback-variables.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LOG_PATH = ./logs
LOG_FILE_NAME = runus
LOG_DATEFORMAT_PATTERN = yyyy-MM-dd HH:mm:ss.SSSX

0 comments on commit 38b2146

Please sign in to comment.