Jump to: navigation, search

Jetty/Feature/Jetty Logging

< Jetty‎ | Feature
Revision as of 14:56, 23 April 2013 by Jesse.mcconnell.gmail.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)



Introduction


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, will have a name, a level, and a message.

The name being 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 - this is used for events considered serious enough to inform and log, but not fatal.
  • INFO - informational events
  • DEBUG - debugging events (very noisy)
  • IGNORE - exception events that can be safely ignored, but might prove useful for some people. (Note: this level might be reported as level DEBUG under some Java logging frameworks configurations, but will retain the 'ignore' phrase somewhere in the logging )

Also note, there is no FATAL or SEVERE events produced by jetty logging.

Selecting the Log Framework

The Jetty logging layer is configured via the org.eclipse.jetty.util.log.Log class and follows these rules.

  1. Load Properties
    1. First from a Classpath Resource called jetty-logging.properties (if found)
    2. Then from the System.getProperties()
  2. Determine the Log implementation.
    1. If property org.eclipse.jetty.util.log.class is defined, load the class it defines as the Logger implementation from the server classpath
    2. If the class org.slf4j.Logger exists in server classpath, then the jetty implementation becomes org.eclipse.jetty.util.log.Slf4jLog
    3. If no logger implementation specified, then default to org.eclipse.jetty.util.log.StdErrLog

Note: that you can create your own custom logging by providing an implementation of the Jetty Logger API. For an example of a custom Logger, see http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java

Configuring Jetty StdErrLog

If the default Jetty logger is selected, then further System properties may be used to control what event levels are logged and what is the format of those logs.

Logging Property Description
<name>.LEVEL=<level> Sets the logging level for all logger 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 would be a package namespace approach to turn all loggers in the jetty HTTP package to DEBUG level, and -Dorg.eclipse.jetty.io.ChanelEndPoint.LEVEL=ALL would turn on all logging events for the specific class, including DEBUG, INFO, WARN (and even special internally ignored exception casses). If a Logging level is specified by more than one system property, then the most specific one is used.
<name>.SOURCE=<boolean> Logger specific, attempt to print the java source file name and line number where the logging event originated from.
Name must be a fully qualified class name (package name hierarchy is not supported by this configurable)
Warning: this is a slow operation and will have an impact on performance!
Default: false
<name>.STACKS=<boolean> Logger specific, control the display of stacktraces.
Name must be a fully qualified class name (package name hierarchy is not supported by this configurable)
Default: true
org.eclipse.jetty.util.log.IGNORED=<boolean> If set to true, then exceptions that have been recorded as ignored with the LOG.ignore(throwable) API will be logged with a full stack trace. Otherwise ignored exceptions are either not logged, or logged in summary if the level is debug.
org.eclipse.jetty.util.log.stderr.SOURCE=<boolean> Special Global Configuration, attempt to print the java source file name and line number where the logging event originated from.
Default: false
org.eclipse.jetty.util.log.stderr.LONG=<boolean> Special Global Configuration, when true, output logging events to STDERR using long form, fully qualified class names. when false, use abbreviated package names
Default: false
org.eclipse.jetty.util.log.DEBUG, org.eclipse.jetty.util.log.stderr.DEBUG, DEBUG (deprecated) These are deprecated properties that are ignored with a warning if used.

Changing log level in resources/jetty-logging.properties

# Setup logging implementation
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=INFO
# Make websocket more verbose for testing
org.eclipse.jetty.websocket.LEVEL=DEBUG

Changing log level in etc/jetty.xml

<Call class="org.eclipse.jetty.util.log.Log" name="getRootLogger">
  <Call name="setDebugEnabled">
    <Arg type="boolean">true</Arg>
  </Call>
</Call>

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

Request Logging

Request logging (AKA access logging), refers to the logging of each request handled by the server. This is a different logging mechanism and in jetty is provided with an implementation of the well-established NCSA log file format. This log file format is standardized so that other tooling can use the information for other reasons.

To enable access logging with Jetty, include the etc/jetty-requestlog.xml on Jetty startup.

See Jetty Request Logs for more information.