Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cant get log4j to run in play! framework 2.2.1 (scala project)

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

like image 670
heiningair Avatar asked Oct 21 '22 18:10

heiningair


1 Answers

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

like image 60
Vidya Avatar answered Oct 23 '22 11:10

Vidya