org.apache.cocoon.util.log
Class ExtensiblePatternFormatter

java.lang.Object
  |
  +--org.apache.cocoon.util.log.ExtensiblePatternFormatter
All Implemented Interfaces:
org.apache.log.format.Formatter
Direct Known Subclasses:
CocoonLogFormatter

public class ExtensiblePatternFormatter
extends java.lang.Object
implements org.apache.log.format.Formatter

A refactoring of org.apache.log.format.PatternFormatter that can be extended. This formater formats the LogEntries according to a input pattern string. The format of each pattern element can be %[+|-]#.#{field:subformat} The +|- indicates left or right justify. The #.# indicates the minimum and maximum size of output. 'field' indicates which field is to be output and must be one of properties of LogEvent 'subformat' indicates a particular subformat and is currently unused.

Version:
CVS $Id: ExtensiblePatternFormatter.java,v 1.4 2002/02/22 07:03:58 cziegeler Exp $
Author:
Peter Donald, Sylvain Wallez

Inner Class Summary
protected static class ExtensiblePatternFormatter.PatternRun
           
 
Field Summary
protected static java.lang.String EOL
           
protected  ExtensiblePatternFormatter.PatternRun[] m_formatSpecification
           
protected static int MAX_TYPE
          The maximum value used for TYPEs.
protected static java.lang.String SPACE_1
           
protected static java.lang.String SPACE_16
           
protected static java.lang.String SPACE_2
           
protected static java.lang.String SPACE_4
           
protected static java.lang.String SPACE_8
           
protected static int TYPE_CATEGORY
           
protected static java.lang.String TYPE_CATEGORY_STR
           
protected static int TYPE_MESSAGE
           
protected static java.lang.String TYPE_MESSAGE_STR
           
protected static int TYPE_PRIORITY
           
protected static java.lang.String TYPE_PRIORITY_STR
           
protected static int TYPE_RELATIVE_TIME
           
protected static java.lang.String TYPE_RELATIVE_TIME_STR
           
protected static int TYPE_TEXT
           
protected static int TYPE_THROWABLE
           
protected static java.lang.String TYPE_THROWABLE_STR
           
protected static int TYPE_TIME
           
protected static java.lang.String TYPE_TIME_STR
           
 
Constructor Summary
ExtensiblePatternFormatter()
           
 
Method Summary
protected  int addPatternRun(java.util.Stack stack, char[] pattern, int index)
          Extract and build a pattern from input string.
protected  int addTextRun(java.util.Stack stack, char[] pattern, int index)
          Extract and build a text run from input string.
protected  void append(java.lang.StringBuffer sb, int minSize, int maxSize, boolean rightJustify, java.lang.String output)
          Utility to append a string to buffer given certain constraints.
protected  void appendWhiteSpace(java.lang.StringBuffer sb, int length)
          Append a certain number of whitespace characters to a StringBuffer.
protected  java.lang.String fix(java.lang.String context)
          Correct a context string by replacing '.''s with a '_'.
 java.lang.String format(org.apache.log.LogEvent event)
          Format the event according to the pattern.
protected  java.lang.String formatPatternRun(org.apache.log.LogEvent event, ExtensiblePatternFormatter.PatternRun run)
          Formats a single pattern run (can be extended in subclasses).
protected  java.lang.String getCategory(java.lang.String category, java.lang.String format)
          Utility method to format category.
protected  java.lang.String getMessage(java.lang.String message, java.lang.String format)
          Utility method to format message.
protected  java.lang.String getPriority(org.apache.log.Priority priority, java.lang.String format)
          Get formatted priority string.
protected  java.lang.String getStackTrace(java.lang.Throwable throwable, java.lang.String format)
          Utility method to format stack trace.
protected  java.lang.String getTime(long time, java.lang.String format)
          Utility method to format time.
protected  int getTypeIdFor(java.lang.String type)
          Retrieve the type-id for a particular string.
protected  void parse(java.lang.String patternString)
          Parse the input pattern and build internal data structures.
 void setFormat(java.lang.String format)
          Set the string description that the format is extracted from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_TEXT

protected static final int TYPE_TEXT

TYPE_CATEGORY

protected static final int TYPE_CATEGORY

TYPE_MESSAGE

protected static final int TYPE_MESSAGE

TYPE_TIME

protected static final int TYPE_TIME

TYPE_RELATIVE_TIME

protected static final int TYPE_RELATIVE_TIME

TYPE_THROWABLE

protected static final int TYPE_THROWABLE

TYPE_PRIORITY

protected static final int TYPE_PRIORITY

MAX_TYPE

protected static final int MAX_TYPE
The maximum value used for TYPEs. Subclasses can define their own TYPEs starting at MAX_TYPE + 1.

TYPE_CATEGORY_STR

protected static final java.lang.String TYPE_CATEGORY_STR

TYPE_MESSAGE_STR

protected static final java.lang.String TYPE_MESSAGE_STR

TYPE_TIME_STR

protected static final java.lang.String TYPE_TIME_STR

TYPE_RELATIVE_TIME_STR

protected static final java.lang.String TYPE_RELATIVE_TIME_STR

TYPE_THROWABLE_STR

protected static final java.lang.String TYPE_THROWABLE_STR

TYPE_PRIORITY_STR

protected static final java.lang.String TYPE_PRIORITY_STR

SPACE_16

protected static final java.lang.String SPACE_16

SPACE_8

protected static final java.lang.String SPACE_8

SPACE_4

protected static final java.lang.String SPACE_4

SPACE_2

protected static final java.lang.String SPACE_2

SPACE_1

protected static final java.lang.String SPACE_1

EOL

protected static final java.lang.String EOL

m_formatSpecification

protected ExtensiblePatternFormatter.PatternRun[] m_formatSpecification
Constructor Detail

ExtensiblePatternFormatter

public ExtensiblePatternFormatter()
Method Detail

addPatternRun

protected int addPatternRun(java.util.Stack stack,
                            char[] pattern,
                            int index)
Extract and build a pattern from input string.
Parameters:
stack - the stack on which to place patterns
pattern - the input string
index - the start of pattern run
Returns:
the number of characters in pattern run

addTextRun

protected int addTextRun(java.util.Stack stack,
                         char[] pattern,
                         int index)
Extract and build a text run from input string. It does special handling of '\n' and '\t' replaceing them with newline and tab.
Parameters:
stack - the stack on which to place runs
pattern - the input string
index - the start of the text run
Returns:
the number of characters in run

append

protected void append(java.lang.StringBuffer sb,
                      int minSize,
                      int maxSize,
                      boolean rightJustify,
                      java.lang.String output)
Utility to append a string to buffer given certain constraints.
Parameters:
sb - the StringBuffer
minSize - the minimum size of output (0 to ignore)
maxSize - the maximum size of output (0 to ignore)
rightJustify - true if the string is to be right justified in it's box.
output - the input string

appendWhiteSpace

protected void appendWhiteSpace(java.lang.StringBuffer sb,
                                int length)
Append a certain number of whitespace characters to a StringBuffer.
Parameters:
sb - the StringBuffer
length - the number of spaces to append

format

public java.lang.String format(org.apache.log.LogEvent event)
Format the event according to the pattern.
Specified by:
format in interface org.apache.log.format.Formatter
Parameters:
event - the event
Returns:
the formatted output

formatPatternRun

protected java.lang.String formatPatternRun(org.apache.log.LogEvent event,
                                            ExtensiblePatternFormatter.PatternRun run)
Formats a single pattern run (can be extended in subclasses).
Parameters:
run - the pattern run to format.
Returns:
the formatted result.

getCategory

protected java.lang.String getCategory(java.lang.String category,
                                       java.lang.String format)
Utility method to format category.
Parameters:
category - the category string
format - ancilliary format parameter - allowed to be null
Returns:
the formatted string

getPriority

protected java.lang.String getPriority(org.apache.log.Priority priority,
                                       java.lang.String format)
Get formatted priority string.

fix

protected final java.lang.String fix(java.lang.String context)
Correct a context string by replacing '.''s with a '_'.
Parameters:
context - the un-fixed context
Returns:
the fixed context

getMessage

protected java.lang.String getMessage(java.lang.String message,
                                      java.lang.String format)
Utility method to format message.
Parameters:
message - the message string
format - ancilliary format parameter - allowed to be null
Returns:
the formatted string

getStackTrace

protected java.lang.String getStackTrace(java.lang.Throwable throwable,
                                         java.lang.String format)
Utility method to format stack trace.
Parameters:
throwable - the throwable instance
format - ancilliary format parameter - allowed to be null
Returns:
the formatted string

getTime

protected java.lang.String getTime(long time,
                                   java.lang.String format)
Utility method to format time.
Parameters:
time - the time
format - ancilliary format parameter - allowed to be null
Returns:
the formatted string

getTypeIdFor

protected int getTypeIdFor(java.lang.String type)
Retrieve the type-id for a particular string.
Parameters:
type - the string
Returns:
the type-id

parse

protected void parse(java.lang.String patternString)
Parse the input pattern and build internal data structures.
Parameters:
patternString - the pattern

setFormat

public void setFormat(java.lang.String format)
Set the string description that the format is extracted from.
Parameters:
format - the string format


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.