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 build.sbt file:

"ch.qos.logback" % "logback-classic" % "1.4.11" % "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 like scala-logging, 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.