Logging

By default, Scalatra uses Logback for logging.

You can easily add logging facilities to your project, if you’ve got the logging dependency in your project/build.scala file:

"ch.qos.logback" % "logback-classic" % "1.2.3" % "runtime"

In your servlet or filter class:

import org.slf4j.{Logger, LoggerFactory}

class YourServlet extends ScalatraServlet {

  val logger =  LoggerFactory.getLogger(getClass)

  get("/") {
    logger.info("foo")
    // whatever else you want to put in the body of the action
  }
}

This will get you basic logging support. There are some additional logging libraries you might want to investigate: scala-logging and grizzled-slf4j, which act as Scala wrappers around slf4j.

The Scala wrappers use by-name parameters for the log message, and check to see that the logging level is enabled. This is a performance win for complex log messages involving expensive toStrings or many concatenations.