我不能让log4j在play框架2.2.1中运行
我使用以下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用法示例:
object SomeService { private val log = Logger.getLogger(this.getClass()) def someMethod() = { log.error("test") } }
如果我运行测试,我会得到以下控制台输出:
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.
请有人帮我这个吗?
非常感谢
解决方法
首先,摆脱log4J的东西(这是2008年),并通过Play附带的SLF4J使用Logback.
Even the authors of log4j would tell you that因为他们也是Logback的作者.
然后创建一个名为application-logger.xml的alternative logback configuration file,并将其复制到Play应用程序的conf文件夹中,以便在部署时加载.
有关使用Play配置Logback的更多信息!框架,见Configuring logging