简体   繁体   English

logback不将perf4j打印到日志文件

[英]logback does not print perf4j to log file

My application is using logback. 我的应用程序正在使用logback。 Now I want to use perf4j 0.9.16 for my current application. 现在,我想在当前应用程序中使用perf4j 0.9.16。 The configuration comes from http://perf4j.codehaus.org/apidocs/org/perf4j/logback/package-summary.html 该配置来自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 is still worked as before but myapp.timer is empty file. myapp.log仍然可以像以前一样工作,但是myapp.timer是空文件。 It logs to console like this: 它像这样记录到控制台:

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

I've tried this perf4j settings for logback.xml , but it can't help. 我已经尝试过将logback.xml设置为perf4j ,但这无济于事。 Any idea? 任何想法?

Thank you. 谢谢。

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

Update. 更新。

With <configuration debug="true"> , application logs: 使用<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.

This happens when you pass your own logger to one of the Slf4JStopWatch constructors. 当您将自己的记录器传递给Slf4JStopWatch构造函数之一时,就会发生这种情况。 Either use the default constructor ( new Slf4JStopWatch() ) or change your config file to something like 使用默认的构造函数( new Slf4JStopWatch() )或将配置文件更改为类似

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

org.perf4j.TimingLogger is just the default logger name for stopwatches. org.perf4j.TimingLogger只是秒表的默认记录器名称。

By the way: One of your <pattern> elements is in capitalized. 顺便说一句: <pattern>元素之一是大写的。

The code looks correct. 该代码看起来正确。 Note that logback loads config from a couple of places, so it's possible that your config isn't used. 请注意,logback从几个地方加载配置,因此有可能未使用您的配置。 To find out what it going on, replace <configuration> with <configuration debug="true"> . 要了解发生了什么,请将<configuration>替换为<configuration debug="true">

Logback will then print it's own setup while it parses the configuration. 然后,Logback将在分析配置时打印其自己的设置。 If you don't see anything, then there is an additional logback.xml file somewhere on the classpath or logback-test.xml or logback.groovy . 如果您什么都没有看到,则在类路径或logback-test.xmllogback.groovy上的某个位置还有一个额外的logback.xml文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM