com.sap.tc.logging
Class Formatter

java.lang.Object
  |
  +--com.sap.tc.logging.Formatter
Direct Known Subclasses:
ListFormatter, TraceFormatter, XMLFormatter

public abstract class Formatter
extends java.lang.Object

Formats log records on behalf of logs the formatter is registered with.

See Also:
Log, LogController

Method Summary
 boolean equals(java.lang.Object obj)
          Compare to Formatter clasess.
abstract  java.lang.String format(LogRecord rec)
          Formats a log record which is then ready to be written to a log.
 java.lang.String getFooter(Log log)
          Returns the footer for a set of formatted records.
 java.lang.String getFormatterName()
          Gets the descriptive name for this formatter.
 FormatterType getFormatterType()
          Returns the type of formatter instance.
If formatter is the predefined classes provided by logging, an explicit formatter type will be returned.
 java.lang.String getHeader(Log log)
          Returns the header for a set of formatted records.
 boolean isCompleteMessage(int messageSize, byte[] message, int delimiterSize, int[] delimiter)
           
 boolean isCompleteMessage(java.lang.String msg)
          Determine if the message string reaches the valid end(delimiter) of a complete message record, according to the format defined by the formatter
 boolean isParsable()
          Return true if this formatter supports message parsing formatted with this formatter.
 boolean isStartMessage(java.lang.String msg)
          Determine if the message string has a valid start of message record
 boolean isStartMsg(int messageSize, byte[] message)
           
 LogRecord parseMsg(byte[] msgChunk)
           
 LogRecord parseMsg(java.lang.String completeMsgData)
          Message written with the specific formatter is read as plain string.
 void setFormatterName(java.lang.String name)
          Sets a descriptive name for this formatter.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

format

public abstract java.lang.String format(LogRecord rec)
Formats a log record which is then ready to be written to a log.
Parameters:
rec - Log record to be formatted
Returns:
Formatted log record

getHeader

public java.lang.String getHeader(Log log)
Returns the header for a set of formatted records.
Parameters:
log - Target log.
Returns:
Header

getFooter

public java.lang.String getFooter(Log log)
Returns the footer for a set of formatted records.
Parameters:
log - Target log
Returns:
Footer

getFormatterType

public final FormatterType getFormatterType()
Returns the type of formatter instance.
If formatter is the predefined classes provided by logging, an explicit formatter type will be returned. See FormatterType for the predefined formatter types used in Logging.
If the formatter is the customized class provided by the users, the full classname will be included with the format type, use getString() to retrieve it.
Returns:
A formatter type

getFormatterName

public java.lang.String getFormatterName()
Gets the descriptive name for this formatter. Can be null.

setFormatterName

public void setFormatterName(java.lang.String name)
Sets a descriptive name for this formatter. An optional courtesy feature for user to easily refer to a formatter. Highly recommended if logviewer tool will be used to browse the output messages. If no name is specified, nothing will be set and the value is null.

equals

public boolean equals(java.lang.Object obj)
Compare to Formatter clasess. Return true if: Formatter.getFormatterName() is equal And Formatter.getFormatterType().toString() is equal
Overrides:
equals in class java.lang.Object

isParsable

public boolean isParsable()
Return true if this formatter supports message parsing formatted with this formatter. Otherwise, return false. See method parseMsg(String).

parseMsg

public LogRecord parseMsg(java.lang.String completeMsgData)
                   throws java.text.ParseException

Message written with the specific formatter is read as plain string. This method parses the content and massages the data into appropriate fields, into a LogRecord structure.

NOTE: UPDATE this method when newer version of format is defined by the formatter.

Parameters:
A - complete message body and its admin data that can span across multiple lines
Returns:
The complete message with its admin data has been broken down and packed in LogRecord. Return Null if formatter does not support parsing.

parseMsg

public LogRecord parseMsg(byte[] msgChunk)
                   throws java.text.ParseException

isCompleteMessage

public boolean isCompleteMessage(java.lang.String msg)
Determine if the message string reaches the valid end(delimiter) of a complete message record, according to the format defined by the formatter

isStartMessage

public boolean isStartMessage(java.lang.String msg)
Determine if the message string has a valid start of message record

isStartMsg

public boolean isStartMsg(int messageSize,
                          byte[] message)

isCompleteMessage

public boolean isCompleteMessage(int messageSize,
                                 byte[] message,
                                 int delimiterSize,
                                 int[] delimiter)