Logback API
Version 0.9.8

ch.qos.logback.access.jetty
Class RequestLogImpl

java.lang.Object
  extended by ch.qos.logback.core.ContextBase
      extended by ch.qos.logback.access.jetty.RequestLogImpl
All Implemented Interfaces:
Context, AppenderAttachable<AccessEvent>, FilterAttachable, org.mortbay.component.LifeCycle, org.mortbay.jetty.RequestLog

public class RequestLogImpl
extends ContextBase
implements org.mortbay.jetty.RequestLog, AppenderAttachable<AccessEvent>, FilterAttachable

This class is logback's implementation of jetty's RequestLog interface.

It can be seen as logback classic's LoggerContext. Appenders can be attached directly to RequestLogImpl and RequestLogImpl uses the same StatusManager as LoggerContext does. It also provides containers for properties.

To configure jetty in order to use RequestLogImpl, the following lines must be added to the jetty configuration file, namely etc/jetty.xml:

    <Ref id="requestLog"> 
      <Set name="requestLog"> 
        <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
      </Set> 
    </Ref>
 
By default, RequestLogImpl looks for a logback configuration file called logback-access.xml, in the same folder where jetty.xml is located, that is etc/logback-access.xml. The logback-access.xml file is slightly different than the usual logback classic configuration file. Most of it is the same: Appenders and Layouts are declared the exact same way. However, loggers elements are not allowed.

It is possible to put the logback configuration file anywhere, as long as it's path is specified. Here is another example, with a path to the logback-access.xml file.

    <Ref id="requestLog"> 
      <Set name="requestLog"> 
        <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
          <Set name="fileName">path/to/logback.xml</Set>
      </Set> 
    </Ref>
 

Here is a sample logback-access.xml file that can be used right away:

    <configuration> 
      <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
        <layout class="ch.qos.logback.access.PatternLayout"> 
          <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL" />
        </layout> 
      </appender> 
      
      <appender-ref ref="STDOUT" /> 
    </configuration>
 

Another configuration file, using SMTPAppender, could be:

    <configuration> 
      <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender">
        <layout class="ch.qos.logback.access.PatternLayout">
          <param name="pattern" value="%remoteIP [%date] %requestURL %statusCode %bytesSent" />
        </layout>
        <param name="From" value="sender@domaine.org" />
        <param name="SMTPHost" value="mail.domain.org" />
         <param name="Subject" value="Last Event: %statusCode %requestURL" />
         <param name="To" value="server_admin@domain.org" />
      </appender>
      <appender-ref ref="SMTP" /> 
    </configuration>
 

A special, module-specific implementation of PatternLayout was implemented to allow http-specific patterns to be used. The PatternLayout provides a way to format the logging output that is just as easy and flexible as the usual PatternLayout. For more information about the general use of a PatternLayout, please refer to logback classic's PatternLayout. For information about logback access' specific PatternLayout, please refer to it's javadoc.

Author:
Ceki Gülcü, Sébastien Pennec

Field Summary
static String DEFAULT_CONFIG_FILE
           
 
Constructor Summary
RequestLogImpl()
           
 
Method Summary
 void addAppender(Appender<AccessEvent> newAppender)
          Add an appender.
 void addFilter(Filter newFilter)
          Add a filter.
 void clearAllFilters()
           
 void detachAndStopAllAppenders()
          Detach all previously added appenders.
 boolean detachAppender(Appender<AccessEvent> appender)
          Detach the appender passed as parameter from the list of appenders.
 Appender<AccessEvent> detachAppender(String name)
          Detach the appender with the name passed as parameter from the list of appenders.
 Appender<AccessEvent> getAppender(String name)
          Get an appender by name.
 FilterReply getFilterChainDecision(Object event)
          Loop through the filters in the chain.
 Filter getFirstFilter()
          Get first filter in the chain.
 boolean isAttached(Appender appender)
          Returns true if the specified appender is in list of attached attached, false otherwise.
 boolean isFailed()
           
 boolean isRunning()
           
 boolean isStarted()
           
 boolean isStarting()
           
 boolean isStopped()
           
 boolean isStopping()
           
 Iterator iteratorForAppenders()
          Get an iterator for appenders contained in the parent object.
 void log(org.mortbay.jetty.Request jettyRequest, org.mortbay.jetty.Response jettyResponse)
           
 void setFileName(String filename)
           
 void start()
           
 void stop()
           
 
Methods inherited from class ch.qos.logback.core.ContextBase
getName, getObject, getProperty, getPropertyMap, getStatusManager, putObject, setName, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONFIG_FILE

public static final String DEFAULT_CONFIG_FILE
Constructor Detail

RequestLogImpl

public RequestLogImpl()
Method Detail

log

public void log(org.mortbay.jetty.Request jettyRequest,
                org.mortbay.jetty.Response jettyResponse)
Specified by:
log in interface org.mortbay.jetty.RequestLog

start

public void start()
Specified by:
start in interface org.mortbay.component.LifeCycle

stop

public void stop()
Specified by:
stop in interface org.mortbay.component.LifeCycle

isRunning

public boolean isRunning()
Specified by:
isRunning in interface org.mortbay.component.LifeCycle

setFileName

public void setFileName(String filename)

isStarted

public boolean isStarted()
Specified by:
isStarted in interface org.mortbay.component.LifeCycle

isStarting

public boolean isStarting()
Specified by:
isStarting in interface org.mortbay.component.LifeCycle

isStopping

public boolean isStopping()
Specified by:
isStopping in interface org.mortbay.component.LifeCycle

isStopped

public boolean isStopped()
Specified by:
isStopped in interface org.mortbay.component.LifeCycle

isFailed

public boolean isFailed()
Specified by:
isFailed in interface org.mortbay.component.LifeCycle

addAppender

public void addAppender(Appender<AccessEvent> newAppender)
Description copied from interface: AppenderAttachable
Add an appender.

Specified by:
addAppender in interface AppenderAttachable<AccessEvent>

iteratorForAppenders

public Iterator iteratorForAppenders()
Description copied from interface: AppenderAttachable
Get an iterator for appenders contained in the parent object.

Specified by:
iteratorForAppenders in interface AppenderAttachable<AccessEvent>

getAppender

public Appender<AccessEvent> getAppender(String name)
Description copied from interface: AppenderAttachable
Get an appender by name.

Specified by:
getAppender in interface AppenderAttachable<AccessEvent>

isAttached

public boolean isAttached(Appender appender)
Description copied from interface: AppenderAttachable
Returns true if the specified appender is in list of attached attached, false otherwise.

Specified by:
isAttached in interface AppenderAttachable<AccessEvent>

detachAndStopAllAppenders

public void detachAndStopAllAppenders()
Description copied from interface: AppenderAttachable
Detach all previously added appenders.

Specified by:
detachAndStopAllAppenders in interface AppenderAttachable<AccessEvent>

detachAppender

public boolean detachAppender(Appender<AccessEvent> appender)
Description copied from interface: AppenderAttachable
Detach the appender passed as parameter from the list of appenders.

Specified by:
detachAppender in interface AppenderAttachable<AccessEvent>

detachAppender

public Appender<AccessEvent> detachAppender(String name)
Description copied from interface: AppenderAttachable
Detach the appender with the name passed as parameter from the list of appenders.

Specified by:
detachAppender in interface AppenderAttachable<AccessEvent>

addFilter

public void addFilter(Filter newFilter)
Description copied from interface: FilterAttachable
Add a filter.

Specified by:
addFilter in interface FilterAttachable

clearAllFilters

public void clearAllFilters()
Specified by:
clearAllFilters in interface FilterAttachable

getFilterChainDecision

public FilterReply getFilterChainDecision(Object event)
Description copied from interface: FilterAttachable
Loop through the filters in the chain. As soon as a filter decides on ACCEPT or DENY, then that value is returned. If all of the filters return NEUTRAL, then NEUTRAL is returned.

Specified by:
getFilterChainDecision in interface FilterAttachable

getFirstFilter

public Filter getFirstFilter()
Description copied from interface: FilterAttachable
Get first filter in the chain.

Specified by:
getFirstFilter in interface FilterAttachable

Logback API
Version 0.9.8

Copyright © 2005-2008 QOS.ch. All Rights Reserved.