Jetty Logo
Version: 9.1.3-SNAPSHOT
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Chapter 21. Jetty Logging

Table of Contents

Configuring Jetty Logging
Configuring Jetty Request Logs
Example: Logging with Apache Log4j
Example: Logging with Java's java.util.logging
Example: Logging with Logback
Example: Capturing Multiple Logging Frameworks with Slf4j
Example: Centralized Logging with Logback
Jetty Dump Tool

This chapter discusses various options for configuring logging.

Configuring Jetty Logging

Jetty provides logging via its own org.eclipse.jetty.util.log.Logger layer, and does not natively use any existing Java logging framework. All logging events, produced via the Jetty logging layer, have a name, a level, and a message. The name is a FQCN (fully qualified class name) similar to how all existing Java logging frameworks operate.

Jetty logging, however, has a slightly different set of levels that it uses internally:

WARN

For events serious enough to inform and log, but not fatal.

INFO

Informational events.

DEBUG

Debugging events (very noisy).

IGNORE

Exception events that you can safely ignore, but useful for some people. You might see this level as DEBUG under some Java logging framework configurations, where it retains the ignore phrase somewhere in the logging.

Note

Jetty logging produces no FATAL or SEVERE events.

Selecting the Log Framework

Configure the Jetty logging layer via the org.eclipse.jetty.util.log.Log class, following these rules.

  1. Load Properties

    • First from a Classpath Resource called jetty-logging.properties (if found).

    • Then from the System.getProperties().

  2. Determine the log implementation.

    • If property org.eclipse.jetty.util.log.class is defined, load the class it defines as the logger implementation from the server classpath.

    • If the class org.slf4j.Logger exists in server classpath, the Jetty implementation becomes org.eclipse.jetty.util.log.Slf4jLog.

    • If no logger implementation is specified, default to org.eclipse.jetty.util.log.StdErrLog.

Note

You can create your own custom logging by providing an implementation of the Jetty Logger API. For an example of a custom logger, see JavaUtilLog.java.

Configuring Jetty StdErrLog

If you select the default Jetty logger (StdErrLog), you can then use further properties (either as system properties or in a jetty-logging.properties as outlined in Selecting the Log Framework) to control event levels to log and to adjust the format of those logs.

<name>.LEVEL=<level>

Sets the logging level for all loggers within the name specified to the level, which can be (in increasing order of restriction) ALL, DEBUG, INFO, WARN, OFF. The name (or hierarchy) can be a specific fully qualified class or a package namespace, for example, -Dorg.eclipse.jetty.http.LEVEL=DEBUG is a package namespace approach to turn all loggers in the Jetty HTTP package to DEBUG level, and -Dorg.eclipse.jetty.io.ChanelEndPoint.LEVEL=ALL turns on all logging events for the specific class, including DEBUG, INFO, WARN (and even special internally ignored exception classes). If more than one system property specifies a logging level, the most specific one applies.

<name>.SOURCE=<boolean>

Named Logger specific, attempts to print the Java source file name and line number from where the logging event originated. Name must be a fully qualified class name (this configurabale does not support package name hierarchy). Default is false. Be aware that this is a slow operation and has an impact on performance.

<name>.STACKS=<boolean>

Named Logger specific, controls the display of stacktraces. Name must be a fully qualified class name (this configurabale does not support package name hierarchy). Default is true.

org.eclipse.jetty.util.log.stderr.SOURCE=<boolean>

Special Global Configuration. Attempts to print the Java source file name and line number from where the logging event originated. Default is false.

org.eclipse.jetty.util.log.stderr.LONG=<boolean>

Special Global Configuration. When true, outputs logging events to STDERR using long form, fully qualified class names. When false, uses abbreviated package names. Default is false.

Deprecated Parameters:

org.eclipse.jetty.util.log.DEBUG

Formerly used to enable DEBUG level logging on any logger used within Jetty (not just Jetty's own logger).

Replaced with using the logger implementation specific configuration and level filtering.

org.eclipse.jetty.util.log.stderr.DEBUG

Formerly used to enable DEBUG level logging on the internal Jetty StdErrLog implementation.

Replaced with -Dorg.eclipse.jetty.LEVEL=DEBUG

DEBUG

Ancient debugging flag that turned on all debugging, even non-logging debugging.

Jetty no longer uses because many third party libraries employ this overly simple property name, which would generate far too much console output.

Changing log level in resources/jetty-logging.properties

  • This sets the Logging Implementation to StdErrLog.

  • Configures the logging level for "org.eclipse.jetty" to be INFO.

  • Configures the logging level for "org.eclipse.jetty.websocket" to be DEBUG.

Changing log level in etc/jetty.xml

This technique, from older versions of Jetty, configures all of the StdErrLog loggers (no other implementations support this) to be logging at DEBUG level.

Using etc/jetty-logging.xml

You can use etc/jetty-logging.xml to take all System.out and System.err output (from any source) and route it to a rolling log file. To do so, include etc/jetty-logging.xml on Jetty startup.

$ java -jar start.jar etc/jetty-logging.xml      

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-04-15T11:43:44-05:00)