Logging and Debugging      Back Index Exit Next

Jetty uses implementations of the org.mortbay.util.LogSink interface to provide debugging and request logging. The org.mortbay.util.OutputStreamLogSink can send logged data to System.err, System.out, a File or any other OutputStream. If output is to a file, then log rollover and aging is supported.

If Jetty is embedded in another application or product, a LogSink implementation can be written to feed log events to the applications native log mechanism.

Request Logging
A LogSink instance may be added to a HttpServer or a HandlerContext to generate a "standard" request log:

    <Configure class="org.mortbay.jetty.Server">
      <!-- other config here -->
      <Set name="LogSink">
        <New class="org.mortbay.util.OutputStreamLogSink">
          <Arg><SystemProperty name="jetty.log" default="./logs"/>/yyyy_mm_dd.request.log</Arg>
          <Set name="retainDays">90</Set>
          <Set name="append">true</Set>
          <Set name="flushOn">false</Set>
        </New>
      </Set>
    </Configure>
Debugging
Debugging information is logged via the collection of LogSinks configured into the static instance of org.mortbay.util.Log. The static instance can be configured via the API, XML or java system properties:
    java -DLOG_FILE=./logs/requests_yyyy_mm_dd.log org.mortbay.jetty.Server
Jetty is instrumented with debugging statments provided by the org.mortbay.util.Code class. It can be configured via the API, XML or java system properties:
    java \
      -DLOG_FILE=./logs/requests_yyyy_mm_dd.log \
      -DDEBUG \
      -DDEBUG_VERBOSE=99 \
      -DDEBUG_PATTERNS="SocketListener,ThreadedServer" \
      org.mortbay.jetty.Server
Sample XML to configure the debugging mechanism is below:
  <Set name="Debug" class="org.mortbay.util.Code" type="boolean">false</Set>
  <Set name="Verbose" class="org.mortbay.util.Code" type="int">0</Set>
  <Set name="DebugPatterns" class="org.mortbay.util.Code" type="String"></Set>

  <Call name="instance" class="org.mortbay.util.Log">
    <Call name="disableLog"/>
    <Call name="add"> 
      <Arg>
        <New class="org.mortbay.util.WriterLogSink">
          <Arg><SystemProperty name="jetty.log" default="./logs"/>/yyyy_mm_dd.log</Arg>
          <Set name="RetainDays">90</Set>
          <Set name="Append">true</Set>
          <Call name="start"/> 
        </New>
      </Arg>
    </Call>
  </Call>
Back Index Exit Next