Posted in Play, Scala

Application Logging Trait

Typically the Play Logger framework works is good enough and is simple configure based on the doco here.

One thing I find handy to avoid a bit of repetition is to wrap the logger in a trait than defines how I like the name spacing to be done.

trait Logger {
  lazy val logger = play.api.Logger("application." + getClass.getName)
}

Then in the consuming class I can just mix in the trait.

object Application extends Controller with Logger  {
  def index = Action {
    logger.debug("A debug")
    Ok(views.html.index("Your new application is ready."))
  }
}
Advertisements