5

I cant get log4j to run in play framework 2.2.1

I use the following log4j.properties:

log4j.rootLogger=INFO
log4j.logger.deng=INFO
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

application.conf:

application.log=INFO
application.log.path=/log4j.properties

scala usage example:

object SomeService {

  private val log = Logger.getLogger(this.getClass())

  def someMethod() = {
      log.error("test")
  }
}

If I run a test I get the following console output:

log4j:WARN No appenders could be found for logger (SomeService.class).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Can someone help me with this please?

Thanks a lot

heiningair
  • 441
  • 1
  • 6
  • 23
  • 2
    at least by default, Play 2 uses the logback library via the slf4j api. any reason not to use that? – Steve Waldman Dec 23 '13 at 21:31
  • Gotta load the properties file. http://stackoverflow.com/questions/2288876/how-to-configure-log4j-with-a-properties-file – Harley Dec 23 '13 at 21:42

1 Answers1

3

First, get rid of the log4J stuff (which is so 2008) and just use the Logback via SLF4J that comes with Play. Even the authors of log4j would tell you that because they are also the authors of Logback.

Then create an alternative logback configuration file called application-logger.xml and copy that to the conf folder of your Play application so it gets loaded on deploy.

For more information on configuring Logback with the Play! framework, see Configuring logging

torbinsky
  • 1,450
  • 10
  • 17
Vidya
  • 29,932
  • 7
  • 42
  • 70