Complete “Scala Logging” Example

后端 未结 3 1756
忘了有多久
忘了有多久 2020-12-23 10:04

I\'m trying to use Typesafe\'s Scala Logging but couldn\'t get it to print any debug message. I expect Scala Logging to print debug message to the default screen but it does

3条回答
  •  既然无缘
    2020-12-23 10:37

    You're close, but you have to declare a logger instance using an SLF4J logger in the apply method for the Logger companion in com.typesafe.scalalogging. In your build.sbt include:

    libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"
    
    libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.10"
    

    Then this will work:

    import com.typesafe.scalalogging._
    import org.slf4j.LoggerFactory
    
    class MyClass extends LazyLogging {
      // ...
      val logger = Logger(LoggerFactory.getLogger(this.getClass))
      logger.debug("Here goes my debug message.")
      // ...
    }
    

    Here is a reference for LoggerFactory. Hope it helps!

提交回复
热议问题