logback 不会将 perf4j 打印到日志文件

logback does not print perf4j to log file

我的应用程序正在使用 logback。现在我想为我当前的应用程序使用 perf4j 0.9.16。配置来自http://perf4j.codehaus.org/apidocs/org/perf4j/logback/package-summary.html

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <FileNamePattern>/var/log/myapp/myapp.log.%d{yyyy-MM-dd}</FileNamePattern>
    </rollingPolicy>
    <encoder>
        <pattern>%d %5p | %t | %-55logger{55} | %m %n</pattern>
    </encoder>
</appender>

<appender name="perf4jFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <FileNamePattern>/var/log/myapp/myapp.timer.%d{yyyy-MM-dd}</FileNamePattern>
    </rollingPolicy>
    <encoder>
        <Pattern>%date %-5level [%thread] %logger{36} [%file:%line] %msg%n</Pattern>
    </encoder>
</appender>

<logger name="org.perf4j.TimingLogger" level="DEBUG" additivity="false">
    <appender-ref ref="perf4jFileAppender"/>
</logger>

<root level="INFO">
    <appender-ref ref="file"/>
</root>

myapp.log 仍然像以前一样工作,但 myapp.timer 是空文件。它像这样记录到控制台:

start[1430914241369] time[4] tag[firstMethod.success] message[OK]
start[1430914241375] time[0] tag[secondMethod.success] message[OK]

我试过这个 perf4j settings for logback.xml,但没用。 有什么想法吗?

谢谢。

===========================================

更新。

使用 <configuration debug="true">,应用程序日志:

14:45:57,434 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/var/app/tomcat/webapps/myapp/WEB-INF/classes/logback.xml]
14:45:57,506 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
14:45:57,512 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Namingappender as [file]
14:45:57,533 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA- Pushing component [rollingPolicy] on top of the object stack.
14:45:57,561 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
14:45:57,563 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use thepattern /var/log/myapp/myapp.log.%d{yyyy-MM-dd} for the active file
14:45:57,569 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/var/log/myapp/myapp.log.%d{yyyy-MM-dd}'.
14:45:57,569 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
14:45:57,572 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Wed May 06     14:45:57 CEST 2015
14:45:57,573 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA- Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:45:57,574 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA- Pushing component [encoder] on top of the object stack.
14:45:57,597 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file] - Active log file name: /var/log/myapp/myapp.log.2015-05-06
14:45:57,597 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file] - File property is set to [null]
14:45:57,598 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
14:45:57,598 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Namingappender as [perf4jFileAppender]
14:45:57,598 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA- Pushing component [rollingPolicy] on top of the object stack.
14:45:57,599 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
14:45:57,599 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use thepattern /var/log/myapp/myapp.timer.%d{yyyy-MM-dd} for the active file
14:45:57,600 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/var/log/myapp/myapp.timer.%d{yyyy-MM-dd}'.
14:45:57,600 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
14:45:57,600 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Wed May 06     14:45:57 CEST 2015
14:45:57,600 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA- Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:45:57,600 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA- Pushing component [encoder] on top of the object stack.
14:45:57,601 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[perf4jFileAppender] - Active log file name: /var/log/myapp/myapp.timer.2015-05-06
14:45:57,601 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[perf4jFileAppender] - File property is set to [null]
14:45:57,601 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.perf4j.TimingLogger] to DEBUG
14:45:57,601 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.perf4j.TimingLogger] to false
14:45:57,601 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [perf4jFileAppender] to Logger[org.perf4j.TimingLogger]
14:45:57,604 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
14:45:57,604 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file] to Logger[ROOT]
14:45:57,604 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

代码看起来正确。请注意,logback 从几个地方加载配置,因此您的配置可能未被使用。要了解发生了什么,请将 <configuration> 替换为 <configuration debug="true">

Logback 将在解析配置时打印它自己的设置。如果您没有看到任何东西,那么在类路径或 logback-test.xmllogback.groovy.

某处有一个额外的 logback.xml 文件

当您将自己的记录器传递给 Slf4JStopWatch 构造函数之一时,就会发生这种情况。使用默认构造函数 (new Slf4JStopWatch()) 或将您的配置文件更改为类似

的内容
<logger name="com.example.MyOwnPerformanceLogger" level="DEBUG" additivity="false">
    <appender-ref ref="perf4jFileAppender"/>
</logger>

org.perf4j.TimingLogger 只是秒表的默认记录器名称。

顺便说一下:您的 <pattern> 元素之一是大写的。