Jetty上的TeeFilter不起作用

时间:2014-06-10 14:25:16

标签: spring logging jetty logback

我遇到一个很大的问题,让Teefilter在我的Jetty服务器上工作。我的应用程序中的所有过滤器都是通过代码配置的,我已经包含了这样的teefilter:

config.addFilter("TeeFilter",
                ch.qos.logback.access.servlet.TeeFilter.class).addMappingForUrlPatterns(null,false,"/*");

我可以告诉你这部分是有效的,因为当我启动服务器时,我可以看到“Teefilter将在此主机上处于活动状态”。但是,我看不到任何http请求被记录。

下面是我在项目的etc文件夹中放置的logback-access.xml:

 <configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>      
      <pattern>%fullRequest%n%n%fullResponse</pattern>
    </encoder>
  </appender>

以下是我项目中的logback-test.xml,它记录了东西。显然,我猜它与logback-access.xml

无关
    <configuration>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/chatonline.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>logs/chatonline-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 10MB -->
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
        </layout>
    </appender>

    <logger name="com.airwatch" level="atlandebug"/>
    <logger name="org.springframework.messaging.simp.stomp" level="debug"/>
    <logger name="ch.qos.logback.access.servlet.TeeFilter" level="debug"/>


    <root level="info">
        <appender-ref ref="FILE"/>
    </root>

</configuration>

我在这里遗漏了什么吗?非常感谢任何帮助

2 个答案:

答案 0 :(得分:1)

您可能仍然启用了默认日志记录。

查看您是否生成了logs/2014_12_19.stderrout.log

如果是这样,那么您必须删除默认日志记录模块,或者更改其角色/目的。

如果你想要enable logback on jetty, here's the instructions

# Make sure you are using a ${jetty.base}
[~]$ mkdir myjettybase
[myjettybase]$ cd myjettybase

# Lets replace the default logging behavior with one from logback
[myjettybase]$ mkdir modules
[myjettybase]$ cd modules
[modules]$ curl -O https://raw.githubusercontent.com/jetty-project/logging-modules/master/logback/logging.mod
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   742  100   742    0     0   2196      0 --:--:-- --:--:-- --:--:--  2201
[modules]$ cd ..

# Now lets enable this (updated) logging module in our start.ini
[mybase]$ java -jar /opt/jetty-distribution-9.2.6.v20141205/start.jar --add-to-start=logging
INFO: logging         initialised in ${jetty.base}/start.ini (appended)
MKDIR: ${jetty.base}/logs
DOWNLOAD: http://central.maven.org/maven2/org/slf4j/slf4j-api/1.6.6/slf4j-api-1.6.6.jar to lib/logging/slf4j-api-1.6.6.jar
DOWNLOAD: http://central.maven.org/maven2/ch/qos/logback/logback-core/1.0.7/logback-core-1.0.7.jar to lib/logging/logback-core-1.0.7.jar
DOWNLOAD: http://central.maven.org/maven2/ch/qos/logback/logback-classic/1.0.7/logback-classic-1.0.7.jar to lib/logging/logback-classic-1.0.7.jar
DOWNLOAD: https://raw.githubusercontent.com/jetty-project/logging-modules/master/logback/logback.xml to resources/logback.xml
DOWNLOAD: https://raw.githubusercontent.com/jetty-project/logging-modules/master/logback/jetty-logging.properties to resources/jetty-logging.properties

# Don't forget to edit the ${jetty.base}/resources/logback.xml

# That's it, feel free to enable any other modules you want/need and then run Jetty
[mybase]$ java -jar /opt/jetty-distribution-9.2.6.v20141205/start.jar

答案 1 :(得分:0)

您需要添加

<Valve className="ch.qos.logback.access.tomcat.LogbackValve"/>

到Tomcat的server.xml。