Is there a way to implement something similar to Lombok's annotation @slf4j
with annotation class in Kotlin?
Right now I have an extension function that instantiates a Logger Factory for me, and I must create these variables in each of my classes just like the example below:
@RestController
@RequestMapping("/api/v1/sample")
class SampleController() {
private val log = logger()
@GetMapping
fun show(): String {
log.info("SOME LOGGING MESSAGE")
return "OK"
}
}
inline fun <reified T> T.logger(): Logger {
if (T::class.isCompanion) {
return LoggerFactory.getLogger(T::class.java.enclosingClass)
}
return LoggerFactory.getLogger(T::class.java)
}
What I want to achieve is something like:
@Logger
@RestController
@RequestMapping("/api/v1/sample")
class SampleController() {
@GetMapping
fun show(): String {
log.info("SOME LOGGING MESSAGE")
return "OK"
}
}