Logging in Scala

前端 未结 14 2015
南旧
南旧 2020-12-07 06:51

What is a good way to do logging in a Scala application? Something that is consistent with the language philosophy, does not clutter the code, and is low-maintenance and uno

相关标签:
14条回答
  • 2020-12-07 07:48

    You should have a look at the scalax library : http://scalax.scalaforge.org/ In this library, there is a Logging trait, using sl4j as backend. By using this trait, you can log quite easily (just use the logger field in the class inheriting the trait).

    0 讨论(0)
  • 2020-12-07 07:49

    Quick and easy forms.

    Scala 2.10 and older:

    import com.typesafe.scalalogging.slf4j.Logger
    import org.slf4j.LoggerFactory
    val logger = Logger(LoggerFactory.getLogger("TheLoggerName"))
    logger.debug("Useful message....")
    

    And build.sbt:

    libraryDependencies += "com.typesafe" %% "scalalogging-slf4j" % "1.1.0"
    

    Scala 2.11+ and newer:

    import import com.typesafe.scalalogging.Logger
    import org.slf4j.LoggerFactory
    val logger = Logger(LoggerFactory.getLogger("TheLoggerName"))
    logger.debug("Useful message....")
    

    And build.sbt:

    libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"
    
    0 讨论(0)
提交回复
热议问题