开发者

Put KotlinLogging Logger call in another file and retain name

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜