Logging in Scala

前端 未结 14 2016
南旧
南旧 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:47

    This is how I got Scala Logging working for me:

    Put this in your build.sbt:

    libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2",
    libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
    

    Then, after doing an sbt update, this prints out a friendly log message:

    import com.typesafe.scalalogging._
    object MyApp extends App with LazyLogging {
      logger.info("Hello there")
    }
    

    If you are using Play, you can of course simply import play.api.Logger for writing log messages: Logger.debug("Hi").

    See the docs for more info.

提交回复
热议问题