简体   繁体   中英

TeeFilter on Jetty doesn't work

I am having a huge problem getting Teefilter to work on my Jetty server. All my filters in my App are configured through code, and I have included teefilter like this:

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

I can tell you this part works because I can see "Teefilter will be active on this host" when I start my server. However, I can't see any http request being logged.

Below is my logback-access.xml placed in the project's etc folder:

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

And below is the logback-test.xml in my project, which logs stuff. Apparently, I am guessing it has nothing to do with 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>

Am I missing something here? Any help is greatly appreciated

Its likely that you have the default logging enabled still.

See if you have a logs/2014_12_19.stderrout.log being generated.

If so, then you have to either remove the default logging module, or change its role/purpose as well.

And for the record, if you want to 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

You'll need to add

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

to Tomcat's server.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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