Skip to content

Commit

Permalink
Merge pull request #71 from dnd-side-project/feat/logger
Browse files Browse the repository at this point in the history
[BLOOM-069] Logger 전역 등록
  • Loading branch information
stophwan authored Aug 21, 2024
2 parents cf9bdde + 3e5dab0 commit e6fc9af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.4.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("io.github.oshai:kotlin-logging-jvm:5.1.4")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("com.h2database:h2")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dnd11th.blooming.common.exception

import dnd11th.blooming.common.util.Logger.Companion.log
import org.springframework.boot.logging.LogLevel
import org.springframework.http.ResponseEntity
import org.springframework.validation.FieldError
Expand All @@ -13,9 +14,15 @@ class GlobalExceptionHandler {
fun handleMyException(exception: MyException): ResponseEntity<ErrorResponse> {
val errorType = exception.errorType
when (errorType.logLevel) {
LogLevel.ERROR -> {}
LogLevel.WARN -> {}
else -> {}
LogLevel.ERROR -> {
log.error { "${"Blooming Exception : {}"} ${errorType.message} $exception" }
}
LogLevel.WARN -> {
log.warn { "${"Blooming Exception : {}"} ${errorType.message} $exception" }
}
else -> {
log.info { "${"Blooming Exception : {}"} ${errorType.message} $exception" }
}
}
return ResponseEntity
.status(errorType.status)
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/dnd11th/blooming/common/util/Logger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dnd11th.blooming.common.util

import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging

class Logger {
companion object {
inline val <reified T> T.log: KLogger
get() = KotlinLogging.logger(T::class.java.name)
}
}

0 comments on commit e6fc9af

Please sign in to comment.