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."))

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s