Danny
Danny

Reputation: 233

Put KotlinLogging Logger call in another file and retain name

With KotlinLogger and SLF4J, I want to do something like

// In Log.kt
val logger = KotlinLogging.logger {}

// In Main.kt after importing logger
fun main() {
  val loggerMain = KotlinLogging.logger {}
  loggerMain.info("Hello world") // Main: Hello world
  
  // I want logger to have the same name as loggerMain instead. 
  logger.info("Hello world") // Log: Hello world 


}

I want to reduce the amount of unnecessary boiler plate if possible, and having to create a variable containing the logger for every scope that needs it is something I want to avoid.

I.e. inside of Log.kt, I want to give the logger the name of whatever file accessed it as if it were declared in that file.

Upvotes: 1

Views: 130

Answers (0)

Related Questions