Logback Logger始终为null

时间:2015-10-26 19:59:57

标签: scala playframework-2.4

我有以下logback配置:

<configuration>

  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

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

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${user.home}/web/logs/lap.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- Daily rollover with compression -->
            <fileNamePattern>application-lap-log-%d{yyyy-MM-dd}.gz</fileNamePattern>
            <!-- keep 30 days worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date{yyyy-MM-dd HH:mm:ss ZZZZ} - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
        </encoder>
    </appender>

  <!--
    The logger name is typically the Java/Scala package name.
    This configures the log level to log at for a package and its children packages.
  -->
  <logger name="root" level="INFO" />
  <logger name="play" level="INFO" />
  <logger name="application" level="DEBUG" />

  <root level="INFO">
      <appender-ref ref="STDOUT" />
      <appender-ref ref="FILE" />
    </root>

    <root level="ERROR">
      <appender-ref ref="STDOUT" />
      <appender-ref ref="FILE" />
    </root>

</configuration>

然后,在我的课堂上,我按如下方式实例化一个记录器:

val logger = play.api.Logger("ApplicationMain")

但是在使用时,就这样:

logger.info("Log something")

我得到NullPointerExceptionlogger为空)。我已经阅读了有关日志记录的Play Framework 2.4文档,但我不知道我在这里做错了什么。有什么想法吗?

0 个答案:

没有答案