Jetty 6 always generates debug logs?

时光毁灭记忆、已成空白 提交于 2019-12-12 01:35:29

问题


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?


回答1:


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




回答2:


The -DDEBUG option is only used if you use the StdErr logger. If it's set-up to use slf4j logging (e.g. 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" />




回答3:


See here on how to control logging: http://docs.codehaus.org/display/JETTY/Debugging



来源:https://stackoverflow.com/questions/3316753/jetty-6-always-generates-debug-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!