Best practices for loggers

Just use Log4j 2 and don’t bother with the class name any longer.

import org.apache.logging.log4j.LogManager

class MyClass {

    companion object {
         private val logger = LogManager.getLogger()
    }
}

The getLogger method (without parameters) creates a logger with the name of the calling class.

1 Like