com.sap.tc.logging
Class TraceFormatter

java.lang.Object
  |
  +--com.sap.tc.logging.Formatter
        |
        +--com.sap.tc.logging.TraceFormatter

public class TraceFormatter
extends Formatter

Formats log records as readable lines.


Constructor Summary
TraceFormatter()
          Configures this trace formatter with the standard formatting pattern "%24d %-40l [%t] %s: %m".
TraceFormatter(java.lang.String pattern)
          Configures this trace formatter with a custom formatting pattern.
 
Method Summary
 java.lang.String format(LogRecord rec)
          Formats a log record which is then ready to be written to a log.
 java.lang.String getPattern()
          Gets the current formatting pattern of this formatter.
 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
 LogRecord parseMsg(byte[] msgChunk)
           
 LogRecord parseMsg(java.lang.String completeMsgData)
          Message written with the specific formatter is read as plain string.
 void setPattern(java.lang.String pattern)
           Configures this trace formatter with a custom formatting pattern.
 
Methods inherited from class com.sap.tc.logging.Formatter
equals, getFooter, getFormatterName, getFormatterType, getHeader, isCompleteMessage, isStartMsg, setFormatterName
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraceFormatter

public TraceFormatter()
Configures this trace formatter with the standard formatting pattern "%24d %-40l [%t] %s: %m".
See Also:
TraceFormatter(java.lang.String)

TraceFormatter

public TraceFormatter(java.lang.String pattern)
Configures this trace formatter with a custom formatting pattern. For a description of these patterns please refer to setPattern(java.lang.String).
Parameters:
pattern - Formatting pattern
See Also:
TraceFormatter()
Method Detail

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
Overrides:
isCompleteMessage in class Formatter

isParsable

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

isStartMessage

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

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.

Overrides:
parseMsg in class 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
Overrides:
parseMsg in class Formatter

getPattern

public java.lang.String getPattern()
Gets the current formatting pattern of this formatter.
Returns:
Formatting pattern
See Also:
setPattern(java.lang.String)

setPattern

public void setPattern(java.lang.String pattern)

Configures this trace formatter with a custom formatting pattern. The pattern allows you to specify the message data fields, with place holders of the form "%[[-]<width>[-]]<type>", interspersed with arbitrary text, that you want to have included in formatted messages.

If you put a dash in front of the <width> of the field to be printed, which is a positive integral number, the field is aligned on the right, in case of a trailing dash it is aligned on the left. If you flank <width> with dashes on both sides, you get a centered field. If you omit the alignment, the field is left-aligned. The <type> that specifies the field can be one of

To print a single %, insert a %%. With group indentation, width is interpreted as the indentation for each level with a standard value of 1, and alignment is ignored. As an example, the standard pattern "%24d %-40l [%t] %s: %m" lets the trace formatter print the date and time of the message in a 24-character column aligned to the left, followed by the right-aligned location truncated from the left to 40 characters, the thread name in brackets, and finally the severity name and the formatted message text separated with a colon. A typical message would then look like this:
May 11, 2001 11:17:42 AM ...g.TraceFormatterTest.testStdPattern() [main] Info: test standard pattern
Place holders that do not match the above syntax are printed as is.

Parameters:
pattern - Formatting pattern
See Also:
getPattern()

format

public java.lang.String format(LogRecord rec)
Description copied from class: Formatter
Formats a log record which is then ready to be written to a log.
Overrides:
format in class Formatter
Following copied from class: com.sap.tc.logging.Formatter
Parameters:
rec - Log record to be formatted
Returns:
Formatted log record