开发者

Put KotlinLogging Logger call in another file and retain name

开发者 https://www.devze.com 2022-12-07 22:45 出处:网络
I want to do something like // In Log.kt val logger = KotlinLogging.logger {} // In Main.kt after importing logger

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

精彩评论

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

关注公众号