Difference between revisions of "Jetty/Feature/Jetty Logging"

From Eclipsepedia

< Jetty‎ | Feature
Jump to: navigation, search
Line 1: Line 1:
  {{Jetty
+
  {{Jetty Reference
 
| introduction =  
 
| introduction =  
  
Line 6: Line 6:
 
With any logging mode, all logged events have a name and a level. The name is a Fully Qualified Class Name (FQCN). The logging framework you choose determines the level. While the meaning of the levels is pretty much the same across logging frameworks, the descriptive identifiers for those levels are different.  
 
With any logging mode, all logged events have a name and a level. The name is a Fully Qualified Class Name (FQCN). The logging framework you choose determines the level. While the meaning of the levels is pretty much the same across logging frameworks, the descriptive identifiers for those levels are different.  
  
 +
| body =
 
}}
 
}}
  
Line 12: Line 13:
 
If Jetty does not discover an slf4j jar on the classpath, then it will use the internal org.eclipse.jetty.util.log.StdErrLog logger.  If an slf4j jar is on the classpath, then slf4j configuration mechanisms are used to select the actual logger used (eg logback, java.util.logging, or log4j,can all be used via slf4j).
 
If Jetty does not discover an slf4j jar on the classpath, then it will use the internal org.eclipse.jetty.util.log.StdErrLog logger.  If an slf4j jar is on the classpath, then slf4j configuration mechanisms are used to select the actual logger used (eg logback, java.util.logging, or log4j,can all be used via slf4j).
  
 +
The logger used may also be controlled by the system property <tt>org.eclipse.jetty.util.log.class</tt>, which can be set to the classname of an implementation of the jetty Logger API.  For an example of a custom Logger, see http://download.eclipse.org/jetty/stable-7/xref/org/eclipse/jetty/util/log/JavaUtilLog.html
  
  
For an example of a custom Logger, see http://download.eclipse.org/jetty/stable-7/xref/org/eclipse/jetty/util/log/JavaUtilLog.html
+
==Configuring Jetty StdErrLog==
==Default Jetty Logging–<tt>org.eclipse.jetty.util.log.StdErrLog</tt>==
+
  
The default Jetty log has one name for all logs, using a system property that turns on DEBUG and reports on predefined events that write to STDERR. You configure logging at startup.
+
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.
 
+
Jetty logging includes some system properties that you can use to control filtering.  For example,
+
<tt>org.eclipse.jetty.util.log.stderr.DEBUG</tt> sets the level filter to DEBUG and higher, with the possible levels being IGNORE, DEBUG, INFO, and WARN. By default, Jetty filters from INFO and above, showing only INFO and WARN logs.
+
 
+
* With StdErrLog you always see INFO and WARN logs. You can add DEBUG and/or IGNORE logs.
+
* With the exception of <tt>org.eclipse.jetty.util.log.class</tt> these system properties take boolean values (''true'' or ''false'').
+
 
+
You set these system properties when you start Jetty.
+
 
+
The following system properties define Jetty Logging:
+
  
 
{| class="jetty-table"
 
{| class="jetty-table"
Line 34: Line 25:
 
! scope=col width="600" | Project
 
! scope=col width="600" | Project
 
|-
 
|-
| <tt>org.eclipse.jetty.util.log.class</tt>
+
| <tt>&lt;some.package&gt;.LEVEL=&lt;level&gt;</tt>
| Sets the implementation class for Jetty Logging. Allows you to use an external logging framework with Jetty.
+
| Sets the logging level for all loggers within the <tt>some.package</tt> java package to the level, which can be INFO, DEBUG, WARN or NONE.  For example, -Dorg.eclipse.jetty.http.LEVEL=DEBUG  would turn all loggers in the jetty HTTP package to DEBUG level.  If a Logging level is specified by more than one system property, then the most specific one is used.
 
|-
 
|-
| <tt>org.eclipse.jetty.util.log.IGNORED</tt>
+
| <tt>org.eclipse.jetty.util.log.IGNORED=&lt;boolean&gt;</tt>
| Shows the IGNORED logging events (ones not deemed pertinent.
+
| 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.
 
|-
 
|-
| <tt>org.eclipse.jetty.util.log.DEBUG</tt> (deprecated)
+
| <tt>org.eclipse.jetty.util.log.stderr.SOURCE=&lt;boolean&gt;</tt>  
| Shows DEBUG events and up.
+
| If set to true, then the source filename and line number of the LOG API call are included in the StdErrLog output
 
|-
 
|-
| <tt>org.eclipse.jetty.util.log.stderr.DEBUG</tt>
+
| <tt>org.eclipse.jetty.util.log.stderr.LONG=&lt;boolean&gt;</tt>  
| Shows DEBUG events and up (for StdErrLog)
+
| If set to true, then the long form FQCN is used in the StdErrLog output (defaults to ''false''). Otherwise FQCN are abbreviated to the form oejh.SomeClass instead of org.eclipse.jetty.http.SomeClass.
 
|-
 
|-
| <tt>org.eclipse.jetty.util.log.SOURCE</tt> (deprecated)
+
| <tt>org.eclipse.jetty.util.log.DEBUG</tt><tt>org.eclipse.jetty.util.log.stderr.DEBUG</tt>, <tt>DEBUG</tt> (deprecated)
| Shows the output of the log.
+
| These are deprecated properties that are ignored with a warning if used.
|-
+
| <tt>org.eclipse.jetty.util.log.stderr.SOURCE</tt>  
+
| Includes the source filename and line number in the StdErrLog output
+
|-
+
| <tt>org.eclipse.jetty.util.log.stderr.LONG</tt>  
+
| Uses the long form FQCN in the StdErrLog output (defaults to ''false'').
+
 
|-
 
|-
 
|}
 
|}
 +
  
 
===Changing log level in <tt>etc/jetty.xml</tt>===
 
===Changing log level in <tt>etc/jetty.xml</tt>===

Revision as of 20:54, 11 April 2012



Contents

Introduction

Jetty provides it's own logging mechanism that can work one of 3 modes: 1) Logging to directly to StdErr using org.eclipse.jetty.util.log.StdErrLog ; 2) Logging via Slf4j to any configured Slf4j log; 3) Logging to a custom logger written against the jetty API.

With any logging mode, all logged events have a name and a level. The name is a Fully Qualified Class Name (FQCN). The logging framework you choose determines the level. While the meaning of the levels is pretty much the same across logging frameworks, the descriptive identifiers for those levels are different.

Selecting the Log Framework

If Jetty does not discover an slf4j jar on the classpath, then it will use the internal org.eclipse.jetty.util.log.StdErrLog logger. If an slf4j jar is on the classpath, then slf4j configuration mechanisms are used to select the actual logger used (eg logback, java.util.logging, or log4j,can all be used via slf4j).

The logger used may also be controlled by the system property org.eclipse.jetty.util.log.class, which can be set to the classname of an implementation of the jetty Logger API. For an example of a custom Logger, see http://download.eclipse.org/jetty/stable-7/xref/org/eclipse/jetty/util/log/JavaUtilLog.html


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.

System Property Project
<some.package>.LEVEL=<level> Sets the logging level for all loggers within the some.package java package to the level, which can be INFO, DEBUG, WARN or NONE. For example, -Dorg.eclipse.jetty.http.LEVEL=DEBUG would turn all loggers in the jetty HTTP package to DEBUG level. If a Logging level is specified by more than one system property, then the most specific one is used.
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> If set to true, then the source filename and line number of the LOG API call are included in the StdErrLog output
org.eclipse.jetty.util.log.stderr.LONG=<boolean> If set to true, then the long form FQCN is used in the StdErrLog output (defaults to false). Otherwise FQCN are abbreviated to the form oejh.SomeClass instead of org.eclipse.jetty.http.SomeClass.
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 etc/jetty.xml

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

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

Using Access Logging

Access logging, also called request logging, refers to a well-established NCSA log file format for all requests that the server processes. 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.