grace.log
Class EventFormat

java.lang.Object
  |
  +--grace.log.EventFormat

public class EventFormat
extends java.lang.Object

This class simply captures all of the formatting functionality into a class rather than have it in a specific Handler. This is to allow any Handler classes to format all or portions of Event text even though the PrintHandler class is the only class producing purely textual output.

Typically, a Handler, such as PrintHandler, will instantiate an EventFormat for each different format it needs to support. In the case of PrintHandler, this is only one. Then, the Handler calls the format(Event) function each time it wants to format an event.

	public void log(Event event) {
	    EventFormat format = new EventFormat();
	    System.out.println(format.format(event));
      }
 

Formatting

event-format is composed of a concatenation of the following items:

time-format is one of the following:

relative-time-format is one of the following:

thread-format is:


Note: to specify the entire hierarchy of group names, use the syntax: %g.%g where the '.', which can be any character, will be used to delimit each thread group name.

class-format is:

filename-format is:

message-format is:

object-format is:

exception-format is:

In this scheme, the current format would be: "%t(%r):%n: %e: %c.%f:%l: %m: %o\n"


Field Summary
static java.lang.String BLACK
           
static java.lang.String BLACK_BACKGROUND
           
static java.lang.String BLUE
           
static java.lang.String BLUE_BACKGROUND
           
static java.lang.String BRIGHT
           
static java.lang.String CYAN
           
static java.lang.String CYAN_BACKGROUND
           
static char ESC
           
static java.lang.String GREEN
           
static java.lang.String GREEN_BACKGROUND
           
static java.lang.String HIGHLIGHT
           
static java.lang.String NO_COLOR
           
static java.lang.String PLAIN
           
static java.lang.String PURPLE
           
static java.lang.String PURPLE_BACKGROUND
           
static java.lang.String rcsid
           
static java.lang.String RED
           
static java.lang.String RED_BACKGROUND
           
static java.lang.String UNDERLINE
           
static java.lang.String WHITE
           
static java.lang.String WHITE_BACKGROUND
           
static java.lang.String YELLOW
           
static java.lang.String YELLOW_BACKGROUND
           
 
Constructor Summary
EventFormat()
          This constructs an EventFormat with the default formatting.
EventFormat(java.lang.String format)
          This constructs an EventFormat with custom formatting.
 
Method Summary
 java.lang.String colorListToColor(java.lang.String colorList)
          Takes a space separated list of string colors and returns a composite color that can be used to set any elements color of this class.
protected  java.lang.String eliminateEndingNewlines(java.lang.String source)
           
protected static java.lang.String expandSpecialChars(java.lang.String string)
          This expands newlines and tab escapes into the actual character.
 java.lang.String format(Event event)
          This converts and returns the given event as a String using a default format or the format set in the EventFormat constructor.
protected  void formatException(java.lang.StringBuffer buffer, java.lang.Exception exception)
          This formats the given exception.
protected  void formatFormattedObject(java.lang.String subFormat, java.lang.StringBuffer buffer, java.lang.String name, java.lang.Object object)
          This function writes the given object to the given buffer using the grace.io.JavaPrintWriter.
protected  void formatGenericObject(java.lang.StringBuffer buffer, java.lang.String subFormat, java.lang.String name, java.lang.Object object)
          This function writes the given object to the given buffer using the given format string.
protected  void formatMessage(java.lang.StringBuffer buffer, java.lang.String subFormat, java.lang.String message)
          This formats a string representation of the given message.
protected  void formatObject(java.lang.StringBuffer buffer, java.lang.String format, java.lang.String message, java.lang.Object object)
          This formats a string representation of the given object.
protected  void formatRelativeTime(java.lang.StringBuffer buffer, java.lang.String subFormat, java.util.Date now)
          This writes the difference in time between now and the start of the application to the given bufferformat.
protected  void formatThreadName(java.lang.StringBuffer buffer, java.lang.String subFormat, java.util.Vector names)
          This writes the given Vector of names to the given buffer assuming the format contains thread name escapes.
protected  void formatTime(java.lang.StringBuffer buffer, java.lang.String subFormat, java.util.Date now)
          This returns a string representation of the current time, formatted according to the previously configured system properties.
protected static java.text.DateFormat getDateFormat(java.lang.String name)
          Utility function used by formatTime(...) to find and return java.text.DateFormat for the given name.
 void setClassnameColor(java.lang.String color)
          Sets the color of the formatted classname.
 void setEventColor(java.lang.String eventType, java.lang.String color)
          Sets color used to print the given event string in each log line.
 void setExceptionColor(java.lang.String color)
          Sets the color of the formatted exception.
 void setExceptionFormat(java.lang.String format)
           
 void setFunctionColor(java.lang.String color)
          Sets the color of the formatted function.
 void setLineColor(java.lang.String event, java.lang.String color)
          Sets color used to print an entire log line whose event type is the given event string.
 void setMessageColor(java.lang.String color)
          Sets the color of the formatted message.
 void setMessageFormat(java.lang.String format)
           
 void setObjectColor(java.lang.String color)
          Sets the color of the formatted object.
 void setObjectFormat(java.lang.String format)
           
 void setObjectTimeFormat(java.text.DateFormat format)
           
 void setRelativeTimeColor(java.lang.String color)
          Sets the color of the formatted relative time.
 void setRelativeTimeFormat(java.lang.String format)
           
 void setThreadColor(java.lang.String color)
          Sets the color of the formatted thread.
 void setThreadFormat(java.lang.String format)
           
 void setTimeColor(java.lang.String color)
          Sets the color of the formatted time.
 void setTimeFormat(java.text.DateFormat format)
           
 void useColors(boolean colors)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rcsid

public static final java.lang.String rcsid

NO_COLOR

public static final java.lang.String NO_COLOR

ESC

public static final char ESC

PLAIN

public static final java.lang.String PLAIN

BRIGHT

public static final java.lang.String BRIGHT

UNDERLINE

public static final java.lang.String UNDERLINE

HIGHLIGHT

public static final java.lang.String HIGHLIGHT

BLACK

public static final java.lang.String BLACK

RED

public static final java.lang.String RED

GREEN

public static final java.lang.String GREEN

YELLOW

public static final java.lang.String YELLOW

BLUE

public static final java.lang.String BLUE

PURPLE

public static final java.lang.String PURPLE

CYAN

public static final java.lang.String CYAN

WHITE

public static final java.lang.String WHITE

BLACK_BACKGROUND

public static final java.lang.String BLACK_BACKGROUND

RED_BACKGROUND

public static final java.lang.String RED_BACKGROUND

GREEN_BACKGROUND

public static final java.lang.String GREEN_BACKGROUND

YELLOW_BACKGROUND

public static final java.lang.String YELLOW_BACKGROUND

BLUE_BACKGROUND

public static final java.lang.String BLUE_BACKGROUND

PURPLE_BACKGROUND

public static final java.lang.String PURPLE_BACKGROUND

CYAN_BACKGROUND

public static final java.lang.String CYAN_BACKGROUND

WHITE_BACKGROUND

public static final java.lang.String WHITE_BACKGROUND
Constructor Detail

EventFormat

public EventFormat()
This constructs an EventFormat with the default formatting. The default formatting set in code, but can be overridden on the command line by setting the appropriate System properties.
See Also:
Log

EventFormat

public EventFormat(java.lang.String format)
This constructs an EventFormat with custom formatting. This formatting overrides the formatting set in code and the formatting specified on the command line by setting.
See Also:
Log
Method Detail

format

public java.lang.String format(Event event)
This converts and returns the given event as a String using a default format or the format set in the EventFormat constructor.

This function parses the format:

Parameters:
event - to convert into a String using the set format
Returns:
string result of converting event using format

formatException

protected void formatException(java.lang.StringBuffer buffer,
                               java.lang.Exception exception)
This formats the given exception.

This function parses the format:

This needs work.


eliminateEndingNewlines

protected java.lang.String eliminateEndingNewlines(java.lang.String source)

formatMessage

protected void formatMessage(java.lang.StringBuffer buffer,
                             java.lang.String subFormat,
                             java.lang.String message)
This formats a string representation of the given message. The setMessageFormat() function always overrides subFormats.

This function parses the format:

Parameters:
buffer - to which to write object
format - from which to format this object
message - object to format

formatFormattedObject

protected void formatFormattedObject(java.lang.String subFormat,
                                     java.lang.StringBuffer buffer,
                                     java.lang.String name,
                                     java.lang.Object object)
This function writes the given object to the given buffer using the grace.io.JavaPrintWriter.
Parameters:
buffer - to which this function should append
object - to append to buffer
name - value's name (should never be null)
pretty - flag given to JavaPrintWriter to control length of output

formatGenericObject

protected void formatGenericObject(java.lang.StringBuffer buffer,
                                   java.lang.String subFormat,
                                   java.lang.String name,
                                   java.lang.Object object)
This function writes the given object to the given buffer using the given format string.

This function parses the format:

Parameters:
buffer - to which this function should append
format - containing text and escape sequences
name - value's name (should never be null)
object - to append to buffer

formatObject

protected void formatObject(java.lang.StringBuffer buffer,
                            java.lang.String format,
                            java.lang.String message,
                            java.lang.Object object)
This formats a string representation of the given object. It uses one of the grace.io.PrintWriters to convert the object to a string.
Parameters:
buffer - to which to write object
format - from which to format this object
message - to use as value's name (should never be null)
object - object to format

formatThreadName

protected void formatThreadName(java.lang.StringBuffer buffer,
                                java.lang.String subFormat,
                                java.util.Vector names)
This writes the given Vector of names to the given buffer assuming the format contains thread name escapes.

This function parses the format:

Parameters:
buffer - to which the names will be written
format - containing thread name escape sequences
names - to be written to buffer according to format

formatRelativeTime

protected void formatRelativeTime(java.lang.StringBuffer buffer,
                                  java.lang.String subFormat,
                                  java.util.Date now)
This writes the difference in time between now and the start of the application to the given bufferformat.

This function parses the format:

Parameters:
buffer - to which the relative time will be written
format - containing relative time format instructions
now - from which the application start time is subtracted to form the difference

formatTime

protected void formatTime(java.lang.StringBuffer buffer,
                          java.lang.String subFormat,
                          java.util.Date now)
This returns a string representation of the current time, formatted according to the previously configured system properties.

This function parses the format:


getDateFormat

protected static java.text.DateFormat getDateFormat(java.lang.String name)
Utility function used by formatTime(...) to find and return java.text.DateFormat for the given name.
Parameters:
name - { short, medium, long, full, }
Returns:
DateFormat corresponding to name

expandSpecialChars

protected static java.lang.String expandSpecialChars(java.lang.String string)
This expands newlines and tab escapes into the actual character. This needed so that the user can enter these special characters on the command line and have them work like in Java. It handles null string by returning null.
Parameters:
string - containing potential escaped newlines and tabs
Returns:
the string with the escaped chars replaced by actual chars or null if string is null.

setObjectFormat

public void setObjectFormat(java.lang.String format)

setObjectTimeFormat

public void setObjectTimeFormat(java.text.DateFormat format)

setTimeFormat

public void setTimeFormat(java.text.DateFormat format)

setRelativeTimeFormat

public void setRelativeTimeFormat(java.lang.String format)

setExceptionFormat

public void setExceptionFormat(java.lang.String format)

setMessageFormat

public void setMessageFormat(java.lang.String format)

setThreadFormat

public void setThreadFormat(java.lang.String format)

useColors

public void useColors(boolean colors)

colorListToColor

public java.lang.String colorListToColor(java.lang.String colorList)
Takes a space separated list of string colors and returns a composite color that can be used to set any elements color of this class. For example, given a property, one can call setEventColor(colorListToColor(property));

setTimeColor

public void setTimeColor(java.lang.String color)
Sets the color of the formatted time.

setRelativeTimeColor

public void setRelativeTimeColor(java.lang.String color)
Sets the color of the formatted relative time.

setExceptionColor

public void setExceptionColor(java.lang.String color)
Sets the color of the formatted exception.

setMessageColor

public void setMessageColor(java.lang.String color)
Sets the color of the formatted message.

setObjectColor

public void setObjectColor(java.lang.String color)
Sets the color of the formatted object.

setThreadColor

public void setThreadColor(java.lang.String color)
Sets the color of the formatted thread.

setClassnameColor

public void setClassnameColor(java.lang.String color)
Sets the color of the formatted classname.

setFunctionColor

public void setFunctionColor(java.lang.String color)
Sets the color of the formatted function.

setEventColor

public void setEventColor(java.lang.String eventType,
                          java.lang.String color)
Sets color used to print the given event string in each log line. This means if the given event type is logged, the text of the event type will be colored the given color.
Parameters:
event - to print in color
color - that can be a concatenation of constant colors in this class.

setLineColor

public void setLineColor(java.lang.String event,
                         java.lang.String color)
Sets color used to print an entire log line whose event type is the given event string.
Parameters:
event - whose line to print in color
color - that can be a concatenation of constant colors in this class.