使用编译时间DI时Play Framework 2.5记录问题

时间:2016-11-16 03:44:18

标签: logging playframework

我有以下logback.xml定义:

<configuration>

  <conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${application.home:-.}/logs/application.log</file>
    <encoder>
      <pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
    </encoder>
  </appender>

  <appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="STDOUT" />
  </appender>

  <logger name="play" level="INFO" />
  <logger name="application" level="INFO" />

  <logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />

  <root level="WARN">
    <appender-ref ref="ASYNCSTDOUT" />
  </root>

</configuration>

以下是我如何使用Logger打印到控制台的示例:

class SupervisorActor(globalChannel: GlobalOutputChannel)
  (implicit s: Scheduler) extends Actor {

  private[this] val subscriptions = CompositeCancelable()

  override def preStart = {
    Logger.info(s"starting Supervisor Actor [$self]")
    ....
    ....
}

我原本希望看到&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;我的application.log或控制台上的语句,但似乎没有打印出来。对于可能出错的任何想法?

1 个答案:

答案 0 :(得分:1)

由于我使用编译时DI,我不得不将以下内容添加到我的应用程序加载器逻辑中:

LoggerConfigurator(newContext.environment.classLoader)
  .foreach(_.configure(newContext.environment))