1

我已将 Perf4j 集成到一个独立的应用程序中。我使用 SLF4J / logback 作为日志系统。

统计信息在 perfs.log 中正确生成,但在 graphs.log 文件中没有生成任何内容。

这是我的 logback.xml 配置文件:

<configuration>
    <appender name="graphs_file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>logs/graphs.log</File>
        <encoder>
            <Pattern>%m%n</Pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>logs/graphs.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="graph_mean" class="org.perf4j.logback.GraphingStatisticsAppender">
        <param name="GraphType" value="Mean"/>
        <param name="TagNamesToGraph" value="g2p-load,p2g-load,phonetize-request,graphetize-request,full-request"/>
        <appender-ref ref="graphs_file"/>
    </appender>

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

    <appender name="log_file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>logs/veriname.log</File>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>logs/veriname.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="coalescer" class="org.perf4j.logback.AsyncCoalescingStatisticsAppender">
        <param name="TimeSlice" value="60000"/>

        <appender-ref ref="graph_mean"/>

        <appender-ref ref="perf_file"/>
    </appender>

    <logger name="org.perf4j.TimingLogger" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="coalescer"/>
    </logger>

    <root>
        <appender-ref ref="console" />
        <appender-ref ref="log_file" />
    </root>
</configuration>

在代码中,我使用:

StopWatch watch = new Slf4JStopWatch("phonetize-request");

奇怪的是,它对 perfs.log 文件中的聚合效果很好,但在 graphs.log 中没有任何反应。

我究竟做错了什么 ?

4

0 回答 0