简体   繁体   中英

Jetty 6 always generates debug logs?

I am using Jetty 6.1.24 to develop a Web Service and my code uses slf4j, as Jetty does, and logging is working fine. What I want to do though is get debug logging from my code but not from Jetty (it's too verbose), but I cannot stop it from logging debug info. There are system properties to set debug mode (-DDEBUG), but not to unset debug mode.

My logback log level is set by the start script by setting the system property 'loglevel' and this in turn sets it in my resources/logback.xml:

<configuration>
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d [%thread] %level %logger - %m%n</Pattern>
    </layout>
  </appender>
  <root level="${loglevel:-INFO}">
    <appender-ref ref="CONSOLE"/>
  </root>
</configuration>

Jetty is either always generating debug logs, which are then ignored by the logger if debug is not enabled, or else it's using logger.isDebugEnabled() to set it's debug mode. Does anyone have any ideas on how to get this working?

I had the same issue after placing slf4j's jar in {jetty}/lib/ext.
I solved it by placing this logback.xml file in {jetty}/resources

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

Note the 'level="info"'.

Explanation :
In this configuration Jetty uses as Logger implementation Slf4jLog.
Slf4jLog, in turn, delegates to Logback's implementation.
The logback.xml tells to logback the log level and to use STDOUT.
From here the standard Jetty behavior is present, except you can configure logging levels via logback.xml
As in the default configuration, you can use jetty-logging.xml if you want.
Off course, you can bypass Jetty's PrintStreams and use Logback's Appenders.
Here the flow in case you use jetty-logging.xml:

SomeClass --> Slf4JLog --> ConsoleAppender--> STDOUT --> RolloverFileOutputStream
 (Jetty)      (Jetty)         (Logback)        (OS)           (Jetty)


Revisions :
Jetty 7.2.2
slf4j 1.6.1
Logback 0.9.26

The -DDEBUG option is only used if you use the StdErr logger. If it's set-up to use slf4j logging (eg you've added slf4j onto your classpath), then all the configuration is handled through your slf4j implementation, and the system properties are ignored.

What you want to do configure logback to turn off debug on the jetty log category.

Something like <logger name="org.mortbay.log" level="INFO" />

请参阅此处以了解如何控制日志记录: http//docs.codehaus.org/display/JETTY/Debugging

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