Skip to content

Commit

Permalink
chore: logger
Browse files Browse the repository at this point in the history
  • Loading branch information
DWL21 committed Feb 9, 2025
1 parent 7ff4166 commit 454ccb2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
9 changes: 7 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ val querydslVersion = "5.0.0"
val feignVersion = "4.2.0"
val springCloudVersion = "2024.0.0"
val mockitoKotlinVersion = "3.2.0"
val loggingVersion = "7.0.3"

java {
toolchain {
Expand All @@ -41,10 +42,13 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion")
implementation("org.springframework.boot:spring-boot-starter-validation:$springBootVersion")
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion")

implementation("org.springframework.boot:spring-boot-starter-logging:$springBootVersion")

implementation("org.springframework.cloud:spring-cloud-starter-openfeign:$feignVersion")
implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer:$feignVersion")

implementation("io.github.oshai:kotlin-logging-jvm:$loggingVersion")


implementation("com.querydsl:querydsl-jpa:$querydslVersion:jakarta")
implementation("com.querydsl:querydsl-apt:$querydslVersion:jakarta")
Expand Down Expand Up @@ -96,4 +100,5 @@ allOpen {

tasks.withType<Test> {
useJUnitPlatform()
}
}

50 changes: 50 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 콘솔에 출력되는 패턴 -->
<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %clr(%5level) %cyan(%logger) - %msg%n"/>
<!-- 파일에 기록되는 패턴 -->
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %5level %logger - %msg%n"/>

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

<!-- 콘솔로그 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>

<!-- 파일로그 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<!-- RollingPocliy: 로그를 나눠서 기록 -->
<!-- SizeAndTimeBasedRollingPolicy: 로그파일을 크기, 시간 기반으로 관리 -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 로그파일명 패턴 -->
<!-- 날짜별로 기록되며 maxFileSize를 넘기면 인덱스(i)를 증가시켜 새로운 이름의 로그파일에 기록을 이어간다 -->
<fileNamePattern>logs/%d{yyyy-MM-dd}/%i.log</fileNamePattern>
<!-- 로그파일 최대사이즈 -->
<maxFileSize>100MB</maxFileSize>
<!-- 생성한 로그파일 관리 일수 -->
<maxHistory>14</maxHistory>
</rollingPolicy>
</appender>

<!-- local -->
<springProfile name="local">
<!-- 전체적인 로그는 INFO 레벨 부터 출력 -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<!-- prod -->
<springProfile name="prod">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</springProfile>
</configuration>

0 comments on commit 454ccb2

Please sign in to comment.