3

By default, Jetty does not log anything with a level higher than WARN, which is inappropriate for fatal errors such as OutOfMemory errors. (Most enterprise ops monitoring teams look for ERRORs in logs, not WARN.)

How can I arrange logging so that these fatal errors are reported at ERROR level?

Channing Walton
  • 3,977
  • 1
  • 30
  • 59

1 Answers1

3

I have found that it is possible to configure logback to adjust logging using a ch.qos.logback.classic.turbo.TurboFilter

Here is an example in Scala that converts all WARN to ERROR for org.eclipse.jetty loggers:

import ch.qos.logback.classic.{Level, Logger}
import ch.qos.logback.classic.turbo.TurboFilter
import ch.qos.logback.core.spi.FilterReply
import org.slf4j.{LoggerFactory, Marker}

/**
* Lift the log level of all WARN events to ERROR as Jetty will not
* log anything above WARN level.
*/
class JettyShoutyFilter extends TurboFilter {
  val myLogger = LoggerFactory.getLogger(getClass)

  override def decide(marker: Marker, logger: Logger, level: Level, format: String, params: Array[AnyRef], t: Throwable): FilterReply = {
    if (isStarted && logger.getName.startsWith("org.eclipse.jetty") && level == Level.WARN && format != null) {
      logger.error(marker, format, params)
      FilterReply.DENY
    } else FilterReply.NEUTRAL
  }
}

Add the logger to your config thus:

<configuration>
    <turboFilter class="JettyShoutyFilter"/>
    ...
Channing Walton
  • 3,977
  • 1
  • 30
  • 59