Logback API
Version 0.9.8

ch.qos.logback.classic
Class PatternLayout

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.LayoutBase<E>
          extended by ch.qos.logback.core.pattern.PatternLayoutBase<LoggingEvent>
              extended by ch.qos.logback.classic.PatternLayout
All Implemented Interfaces:
Layout<LoggingEvent>, ContextAware, LifeCycle

public class PatternLayout
extends PatternLayoutBase<LoggingEvent>

A flexible layout configurable with pattern string. The goal of this class is to format a LoggingEvent and return the results in a {#link String}. The format of the result depends on the conversion pattern.

For more information about this layout, please refer to the online manual at http://logback.qos.ch/manual/layouts.html#PatternLayout


Field Summary
static Map<String,String> defaultConverterMap
           
 
Fields inherited from class ch.qos.logback.core.LayoutBase
started
 
Fields inherited from interface ch.qos.logback.core.Layout
LINE_SEP, LINE_SEP_LEN
 
Constructor Summary
PatternLayout()
           
 
Method Summary
static boolean chainHandlesThrowable(Converter head)
          This method computes whether a chain of converters handles exceptions or not.
 String doLayout(LoggingEvent event)
          Transform an event (of type Object) and return it as a String after appropriate formatting.
 Map<String,String> getDefaultConverterMap()
          Concrete implementations of this class are responsible for elaborating the mapping between pattern words and converters.
protected  void postCompileProcessing(Converter<LoggingEvent> head)
          This implementation checks if any of the converters in the chain handles exceptions.
 
Methods inherited from class ch.qos.logback.core.pattern.PatternLayoutBase
findTail, getEffectiveConverterMap, getInstanceConverterMap, getPattern, setContextForConverters, setPattern, start, toString, writeLoopOnConverters
 
Methods inherited from class ch.qos.logback.core.LayoutBase
getContentType, getContext, getFileFooter, getFileHeader, getPresentationFooter, getPresentationHeader, isStarted, setContext, setFileFooter, setFileHeader, setPresentationFooter, setPresentationHeader, stop
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getStatusManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn
 

Field Detail

defaultConverterMap

public static final Map<String,String> defaultConverterMap
Constructor Detail

PatternLayout

public PatternLayout()
Method Detail

postCompileProcessing

protected void postCompileProcessing(Converter<LoggingEvent> head)
This implementation checks if any of the converters in the chain handles exceptions. If not, then this method adds a ThrowableInformationConverter instance to the end of the chain.

This allows appenders using this layout to output exception information event if the user forgets to add %ex to the pattern. Note that the appenders defined in the Core package are not aware of exceptions nor LoggingEvents.

If for some reason the user wishes to NOT print exceptions, then she can add %nopex to the pattern.

Overrides:
postCompileProcessing in class PatternLayoutBase<LoggingEvent>

getDefaultConverterMap

public Map<String,String> getDefaultConverterMap()
Description copied from class: PatternLayoutBase
Concrete implementations of this class are responsible for elaborating the mapping between pattern words and converters.

Specified by:
getDefaultConverterMap in class PatternLayoutBase<LoggingEvent>
Returns:
A map associating pattern words to the names of converter classes

chainHandlesThrowable

public static boolean chainHandlesThrowable(Converter head)
This method computes whether a chain of converters handles exceptions or not.

Parameters:
head - The first element of the chain
Returns:
true if can handle throwables contained in logging events

doLayout

public String doLayout(LoggingEvent event)
Description copied from interface: Layout
Transform an event (of type Object) and return it as a String after appropriate formatting.

Taking in an object and returning a String is the least sophisticated way of formatting events. However, it is remarkably CPU-effective.

Parameters:
event - The event to format
Returns:
the event formatted as a String

Logback API
Version 0.9.8

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