Logback API
Version 0.9.8

ch.qos.logback.access.tomcat
Class LogbackValve

java.lang.Object
  extended by org.apache.catalina.valves.ValveBase
      extended by ch.qos.logback.access.tomcat.LogbackValve
All Implemented Interfaces:
Context, AppenderAttachable<AccessEvent>, FilterAttachable, MBeanRegistration, org.apache.catalina.Contained, org.apache.catalina.Valve

public class LogbackValve
extends org.apache.catalina.valves.ValveBase
implements Context, AppenderAttachable<AccessEvent>, FilterAttachable

This class is an implementation of tomcat's Valve interface, by extending ValveBase. It can be seen as logback classic's LoggerContext. Appenders can be attached directly to LogbackValve and LogbackValve uses the same StatusManager as LoggerContext does. It also provides containers for properties.

To configure tomcat in order to use LogbackValve, the following lines must be added to the tomcat's server.xml, nested in an Engine element:

<Valve className="ch.qos.logback.access.tomcat.LogbackValve"/>

By default, LogbackValve looks for a logback configuration file called logback-access.xml, in the same folder where the tomcat configuration is located, that is $TOMCAT_HOME/conf/logback-access.xml. The format of logback-access configuration file is only slightly different than for logback-classic. Most of it remains the same: Appenders and Layouts are declared the same way. However, since logback-access has no notion of declared loggers, logger elements are not allowed.

Here is a sample logback.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>
 
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
           
 
Fields inherited from class org.apache.catalina.valves.ValveBase
container, containerLog, controller, domain, info, mserver, next, oname
 
Constructor Summary
LogbackValve()
           
 
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 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.
 String getInfo()
           
 String getName()
          Contexts are named objects.
 Object getObject(String key)
          A Context can act as a store for various objects used by LOGBack components.
 String getProperty(String key)
          Get the property of this context.
 Map<String,String> getPropertyMap()
          Get all the properties for this context as a Map.
 StatusManager getStatusManager()
           
 void invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)
           
 boolean isAttached(Appender appender)
          Returns true if the specified appender is in list of attached attached, false otherwise.
 Iterator iteratorForAppenders()
          Get an iterator for appenders contained in the parent object.
 void putObject(String key, Object value)
          Store an object under 'key'.
 void setName(String name)
          The name of the context can be set only once.
 void setProperty(String key, String val)
          Set a property of this context.
 void start()
           
 void stop()
           
 
Methods inherited from class org.apache.catalina.valves.ValveBase
backgroundProcess, createObjectName, getContainer, getContainerName, getController, getDomain, getNext, getObjectName, getParentName, postDeregister, postRegister, preDeregister, preRegister, setContainer, setController, setNext, setObjectName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONFIG_FILE

public static final String DEFAULT_CONFIG_FILE
Constructor Detail

LogbackValve

public LogbackValve()
Method Detail

start

public void start()

invoke

public void invoke(org.apache.catalina.connector.Request request,
                   org.apache.catalina.connector.Response response)
            throws IOException,
                   ServletException
Specified by:
invoke in interface org.apache.catalina.Valve
Specified by:
invoke in class org.apache.catalina.valves.ValveBase
Throws:
IOException
ServletException

stop

public void stop()

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 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>

getInfo

public String getInfo()
Specified by:
getInfo in interface org.apache.catalina.Valve
Overrides:
getInfo in class org.apache.catalina.valves.ValveBase

getStatusManager

public StatusManager getStatusManager()
Specified by:
getStatusManager in interface Context

getPropertyMap

public Map<String,String> getPropertyMap()
Description copied from interface: Context
Get all the properties for this context as a Map. Note that the returned cop might be a copy not the original. Thus, modifying the returned Map will have no effect (on the original.)

Specified by:
getPropertyMap in interface Context
Returns:

setProperty

public void setProperty(String key,
                        String val)
Description copied from interface: Context
Set a property of this context.

Specified by:
setProperty in interface Context

getProperty

public String getProperty(String key)
Description copied from interface: Context
Get the property of this context.

Specified by:
getProperty in interface Context

getObject

public Object getObject(String key)
Description copied from interface: Context
A Context can act as a store for various objects used by LOGBack components.

Specified by:
getObject in interface Context
Returns:
The object stored under 'key'.

putObject

public void putObject(String key,
                      Object value)
Description copied from interface: Context
Store an object under 'key'. If no object can be found, null is returned.

Specified by:
putObject in interface Context

addFilter

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

Specified by:
addFilter in interface FilterAttachable

getFirstFilter

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

Specified by:
getFirstFilter 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

getName

public String getName()
Description copied from interface: Context
Contexts are named objects.

Specified by:
getName in interface Context
Returns:
the name for this context

setName

public void setName(String name)
Description copied from interface: Context
The name of the context can be set only once.

Specified by:
setName in interface Context

Logback API
Version 0.9.8

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