LoggerFactory로 생성하고 직접 클래스 지정
@Component
class MyLogTester {
private val log = LoggerFactory.getLogger(MyLogTester::class.java)
fun log() {
log.info("Test Log")
}
}
2024-01-14T13:31:27.447+09:00 INFO 10908 --- [ main] c.example.ktorsamplespring.MyLogTester : Test Log
@Component
class MyLogTester {
private val log = LoggerFactory.getLogger(this.javaClass)
...
}
inline fun<reified T> T.logger() =
LoggerFactory.getLogger(T::class.java)
@Component
class MyLogTester {
private val log = logger()
...
}
class LoggerDelegator {
private var logger: Logger? = null
operator fun getValue(thisRef: Any?, property: Any?): Logger =
logger ?: LoggerFactory.getLogger(thisRef?.javaClass)
}
@Component
class MyLogTester {
private val log by LoggerDelegator()
...
}
gradle
implementation 'io.github.microutils:kotlin-logging:3.0.5'
import mu.KotlinLogging
import org.springframework.stereotype.Component
@Component
class MyLogTester {
private val log = KotlinLogging.logger {}
...
}