org.jcoderz.commons.logging
Class LogLineFormat

java.lang.Object
  extended by org.jcoderz.commons.logging.LogLineFormat
Direct Known Subclasses:
BasicLogLineFormat, ContinuationLineFormat

public abstract class LogLineFormat
extends Object

This is the base class for various log line formats. It gives the defined types of log lines and a common interface for formatting and parsing different types of log lines.


Nested Class Summary
static class LogLineFormat.LogLineType
          This helper class is used as type safe enumeration for all defined log line types.
 
Field Summary
protected static Format[] EMPTY_FORMATTERS
           
static LogLineFormat.LogLineType ERROR_MESSAGE
          Used for Loggable logs carrying a Throwable or being derived from a Throwable.
static LogLineFormat.LogLineType EXCEPTION_MESSAGE
          Used for standard LogRecord logs carrying a Throwable.
static LogLineFormat.LogLineType LOG_MESSAGE
          Used for Loggable logs.
static LogLineFormat.LogLineType NESTED_MESSAGE
          Used for nested loggables.
static LogLineFormat.LogLineType PARAMETER_LINE
          Used for logging parameters as name and value list.
protected static int SOURCECLASS_INDEX
          Index for source class name within String array as it is returned by getLogSource(String).
protected static int SOURCEMETHOD_INDEX
          Index for source method name within String array as it is returned by getLogSource(String).
static LogLineFormat.LogLineType STACKTRACE_MESSAGE
          Used for stack trace elements of logged Throwables.
static LogLineFormat.LogLineType TRACE_MESSAGE
          Used for standard LogRecord logs.
 
Constructor Summary
protected LogLineFormat(LogLineFormat.LogLineType type, MessageFormat format, int numberOfArguments)
          Creates and initializes a new instance of this.
 
Method Summary
protected  void format(StringBuffer sb)
          Formats all parameters set so far into the supplied StringBuffer using the encapsulated MessageFormat.
abstract  void format(StringBuffer sb, LogRecord record, Loggable loggable, List trackingIdSequence, Throwable thrown, Object parameter)
          The common interface for all log line formatters.
protected static Format getBusinessImpactFormat()
          Gets the format to use for formatting the business impact element.
protected static Format getCategoryFormat()
          Gets the format to use for formatting the category element.
protected static Format getInstanceIdFormat()
          Gets the format to use for formatting an instance id element.
protected static Format getLoggerLevelFormat()
          Gets the format to use for formatting the logger /severity level element.
static LogLineFormat.LogLineType getLogLineType(char code)
          Gets the LogLineType matching the supplied code.
protected  String[] getLogSource(String source)
          Gets the source class name and source method name where the Log record was logged from the supplied string.
protected static Format getMessageSymbolFormat()
          Gets the format to use for formatting a symbol id element.
protected static Format getNodeIdFormat()
          Gets the format to use for formatting a node id element.
protected  Object getParameter(int index)
          Gets the parameter at the specified position.
protected static Format getThreadIdFormat()
          Gets the format to use for formatting a thread id element.
protected static Format getThreadNameFormat()
          Gets the format to use for formatting the thread name element.
protected static Format getTimestampFormat()
          Gets the format to use for formatting a timestamp element.
protected static Format getTrackingNumberFormat()
          Gets the format to use for formatting the tracking numbers
protected  void parse(StringBuffer sb)
          Parses the supplied StringBuffer from beginning to end with the encapsulated MessageFormat.
abstract  void parse(StringBuffer sb, LogFileEntry entry)
          The common interface for all log line formatters.
protected  void setFormats(Format[] formats)
          Sets the contributing formats for the encapsulated MessageFormat.
protected  void setParameter(int index, Object obj)
          Sets a parameter at the specified position to be used when formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE_MESSAGE

public static final LogLineFormat.LogLineType TRACE_MESSAGE
Used for standard LogRecord logs.


EXCEPTION_MESSAGE

public static final LogLineFormat.LogLineType EXCEPTION_MESSAGE
Used for standard LogRecord logs carrying a Throwable.


LOG_MESSAGE

public static final LogLineFormat.LogLineType LOG_MESSAGE
Used for Loggable logs.


ERROR_MESSAGE

public static final LogLineFormat.LogLineType ERROR_MESSAGE
Used for Loggable logs carrying a Throwable or being derived from a Throwable.


NESTED_MESSAGE

public static final LogLineFormat.LogLineType NESTED_MESSAGE
Used for nested loggables.


STACKTRACE_MESSAGE

public static final LogLineFormat.LogLineType STACKTRACE_MESSAGE
Used for stack trace elements of logged Throwables.


PARAMETER_LINE

public static final LogLineFormat.LogLineType PARAMETER_LINE
Used for logging parameters as name and value list.


EMPTY_FORMATTERS

protected static final Format[] EMPTY_FORMATTERS

SOURCECLASS_INDEX

protected static final int SOURCECLASS_INDEX
Index for source class name within String array as it is returned by getLogSource(String).

See Also:
Constant Field Values

SOURCEMETHOD_INDEX

protected static final int SOURCEMETHOD_INDEX
Index for source method name within String array as it is returned by getLogSource(String).

See Also:
Constant Field Values
Constructor Detail

LogLineFormat

protected LogLineFormat(LogLineFormat.LogLineType type,
                        MessageFormat format,
                        int numberOfArguments)
Creates and initializes a new instance of this.

Parameters:
type - The type of this.
format - The MessageFormat used for formatting and parsing a log line of this type.
numberOfArguments - The number of arguments for the supplied message format.
Method Detail

format

public abstract void format(StringBuffer sb,
                            LogRecord record,
                            Loggable loggable,
                            List trackingIdSequence,
                            Throwable thrown,
                            Object parameter)
The common interface for all log line formatters. Not all parameters might be used for implementations of this. Common for all implementation is that they append a line feed after the data has been formatted into the StringBuffer.

Parameters:
sb - The StringBuffer where to append the formatted data.
record - THe LogRecord to format.
loggable - The Loggable to format.
trackingIdSequence - The sequence of contributing tracking ids.
thrown - The Throwable to format.
parameter - An additional parameter, which might be required for an implementation of this.

parse

public abstract void parse(StringBuffer sb,
                           LogFileEntry entry)
                    throws ParseException
The common interface for all log line formatters. A log line is parsed and the data being retrieved is set within the supplied LogFileEntry.

Parameters:
sb - The StringBuffer containing the log line to parse from the current position to the end.
entry - The LogFileEntry which gets the data being parsed.
Throws:
ParseException - if an error occurs parsing the log line.

getLogLineType

public static LogLineFormat.LogLineType getLogLineType(char code)
                                                throws IllegalArgumentException
Gets the LogLineType matching the supplied code.

Parameters:
code - The code for the LogLineType to return.
Returns:
LogLineType with code matching code.
Throws:
IllegalArgumentException - if no such LogLineType.

setFormats

protected final void setFormats(Format[] formats)
Sets the contributing formats for the encapsulated MessageFormat.

Parameters:
formats - The formats to set.

setParameter

protected final void setParameter(int index,
                                  Object obj)
Sets a parameter at the specified position to be used when formatting.

Parameters:
index - The index at which to set the parameter. It must hold true 0 <= index < num parameters with num parameter being the number set when creating this.
obj - The object to set at the supplied position.

getParameter

protected final Object getParameter(int index)
Gets the parameter at the specified position.

Parameters:
index - The index from which to get the parameter. It must hold true 0 <= index < num parameters with num parameter being the number set when creating this.
Returns:
The object at the supplied position.

format

protected final void format(StringBuffer sb)
Formats all parameters set so far into the supplied StringBuffer using the encapsulated MessageFormat.

Parameters:
sb - The StringBuffer into which to format the data.

parse

protected final void parse(StringBuffer sb)
                    throws ParseException
Parses the supplied StringBuffer from beginning to end with the encapsulated MessageFormat. The parsed objects can be accessed by calling getParameter(int) with the appropriate index.

Parameters:
sb - The StringBuffer from which to parse the parameter values.
Throws:
ParseException - if an error occurs parsing the string.

getThreadIdFormat

protected static final Format getThreadIdFormat()
Gets the format to use for formatting a thread id element.

Returns:
Format for formatting the thread id.

getTimestampFormat

protected static final Format getTimestampFormat()
Gets the format to use for formatting a timestamp element.

Returns:
Format for formatting the timestamp.

getNodeIdFormat

protected static final Format getNodeIdFormat()
Gets the format to use for formatting a node id element.

Returns:
Format for formatting the node id.

getInstanceIdFormat

protected static final Format getInstanceIdFormat()
Gets the format to use for formatting an instance id element.

Returns:
Format for formatting the instance id.

getLoggerLevelFormat

protected static final Format getLoggerLevelFormat()
Gets the format to use for formatting the logger /severity level element.

Returns:
Format for formatting the logger level.

getMessageSymbolFormat

protected static final Format getMessageSymbolFormat()
Gets the format to use for formatting a symbol id element.

Returns:
Format for formatting the message symbol.

getBusinessImpactFormat

protected static final Format getBusinessImpactFormat()
Gets the format to use for formatting the business impact element.

Returns:
Format for formatting the business impact.

getCategoryFormat

protected static final Format getCategoryFormat()
Gets the format to use for formatting the category element.

Returns:
Format for formatting the category.

getThreadNameFormat

protected static final Format getThreadNameFormat()
Gets the format to use for formatting the thread name element.

Returns:
Format for formatting the category.

getTrackingNumberFormat

protected static final Format getTrackingNumberFormat()
Gets the format to use for formatting the tracking numbers

Returns:
Format for formatting the tracking numbers.

getLogSource

protected final String[] getLogSource(String source)
Gets the source class name and source method name where the Log record was logged from the supplied string. Use SOURCECLASS_INDEX and SOURCEMETHOD_INDEX for accessing the appropriate values in the string array being returned.

Parameters:
source - the log source in format classname.methodname
Returns:
String array with source class name as first and source method name as second parameter.


Copyright 2007 The jCoderZ Project.