Sheshank Kodam
Sheshank Kodam

Reputation: 515

Load logback configurations based on environment with Scala Play2.5

I would like to load different logback configurations based on SCALA_ENV environmental variable.

  1. if SCALA_ENV=PROD load logback.xml
  2. if SCALA_ENV=dev load logback-dev.xml
  3. if SCALA_ENV=test load logback-test.xml
  4. if SCALA_ENV=qa load logback-qa.xml

From Play2.5 docuemntation i found this example but it is not clear.
enter image description here

Also MyComponenets is unresolved and compilation fails.

Upvotes: 1

Views: 316

Answers (2)

Sheshank Kodam
Sheshank Kodam

Reputation: 515

Not an ideal solution but I'm changed the -Dlogger.resource file based on environment in build.sbt

 lazy val logBackXml = sys.env("env").toLowerCase() match {
      case "prod" => "-Dlogger.resource=logback.xml"
      case "test" => "-Dlogger.resource=logback.test.xml"
      case "qa"   => "-Dlogger.resource=logback.qa.xml"
      case _      => "-Dlogger.resource=logback.dev.xml"
 }

 javaOptions in Production += logBackXml

Upvotes: 0

Tyler
Tyler

Reputation: 18157

This is how I do it in my build.sbt file:

// logback for Prod
javaOptions in Production += "-Dlogger.resource=logback.prod.xml"

// logback for testing
javaOptions in Test += "-Dlogger.resource=logback.test.xml"

My default one is the dev, which is just left at the default location.

Upvotes: 1

Related Questions