<@U0MEUGTCM> Hello oshai! i have a question about ...
# kotlin-logging
u
@oshai Hello oshai! i have a question about how to declare kotlin Logger! i have two cases using kotlin logger. They are under the below. 1. Declare K Logger as a member property of Spring Bean class 2. Declare top-level property of the file and sharing it on the same file. I read the recommended way that is no 2. But K Logger with Spring Bean, the logger’s life cycle is same with the spring bean, so there are no bad thing as a member property i think. What is your opinion and what is the recommended way?
o
can you share an example? as you said 2 is the recommended way. it's also not clear to me if 1 is a static member as a logger field should be. logger does not care about the normal lifecycle of a bean. it's a resource per class
u
@oshai no 1 code is here!
Copy code
@Service
class SomeBusinessService {

    private val logger = KotlinLogging.logger {}

    fun execute() {
        // do something
    }
}
o
yes, so this is not recommended. even though a
@Service
might be a singleton or not, you don't want to tie the logger lifecycle to that (in case you change in the future). so out of the class is better.
🙌 1