edu.isi.ikcap.workflows.util.logging
Class EventLogMessage

java.lang.Object
  extended by edu.isi.ikcap.workflows.util.logging.EventLogMessage

public class EventLogMessage
extends Object

This is a modification of gov.lbl.netlogger.LogMessage This class lets you easily construct a set of typed (name, value) pairs that formats itself as a CEDPS Best Practices log message.

Name and value pairs are added into the record with add() methods which, by virtue of returning the newly modified LogMessage instance, can be chained together.

The user can set the timestamp to something other than the time of the call by calling setTimeStamp{Millis,Nanos}() as part of the chain.

To format the message, call toString(). The output format is CEDPS "Best Practices" format.

Since the addition of the nanosecond timestamp (which is rounded down to microseconds, and no I don't want to discuss it), this class requires Java 1.5

Author:
Dan Gunter dkgunter@lbl.gov, Wolfgang Hoschek whoschek@lbl.gov, Paul Groth pgroth@isi.edu

Nested Class Summary
private static class EventLogMessage.Log4jFilter
          In log4j, ignore all messages not specifically directed at this appender.
 
Field Summary
static String APPENDER
           
private  StringBuffer buf
           
private static GregorianCalendar calendar
           
static String DATE_KW
           
private  int dateEnd
           
private  int dateStart
           
private static char[] DIGIT
           
private static Escape escape
           
static String EVENT_KW
           
static String FAKE_DATE
           
private static SimpleDateFormat format
           
static String LEVEL_KW
           
private static long micro0
           
private static long micro1
           
private  long micro2
           
private static long nano0
           
private static String timeString
           
private static Lock timeStringLock
           
private  int usecEnd
           
private  int usecStart
           
 
Constructor Summary
protected EventLogMessage(String eventName)
          Create a new LogMessage at the current time with a given event name.
 
Method Summary
 EventLogMessage add(String key, double value)
          Add a double.
 EventLogMessage add(String key, float value)
          Add a float.
 EventLogMessage add(String key, int value)
          Add an int.
 EventLogMessage add(String key, long value)
          Add a long.
 EventLogMessage add(String key, String value)
          Add a string.
 EventLogMessage addList(String key, List list)
           
 EventLogMessage addMap(String key, Map map)
          Add a Map to the buffer.
 EventLogMessage addMsg(String msg)
          Add an natural language message to the log message.
 EventLogMessage addPair(String key, String pairKey, String pairValue)
          Add a key,value pair The result looks like: key = (pairKey, pairValue)
 EventLogMessage addTime(String key, long timeInMillis)
           
private  void addTimeStamp()
          Add a timestamp to the message.
 EventLogMessage addWQ(String key, String value)
          Add a string.
 EventLogMessage setTimeStampMillis(long millis)
          Set the timestamp from milliseconds returned by System.currentTimeMillis().
 EventLogMessage setTimeStampNanos(long nano1)
          Set the timestamp from nanoseconds returned by System.nanoTime().
 String toString()
          Format a message in CEDPS Best Practices format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buf

private final StringBuffer buf

micro0

private static long micro0

nano0

private static long nano0

micro1

private static long micro1

micro2

private long micro2

timeString

private static String timeString

format

private static SimpleDateFormat format

calendar

private static final GregorianCalendar calendar

timeStringLock

private static Lock timeStringLock

APPENDER

public static final String APPENDER
See Also:
Constant Field Values

EVENT_KW

public static final String EVENT_KW
See Also:
Constant Field Values

DATE_KW

public static final String DATE_KW
See Also:
Constant Field Values

FAKE_DATE

public static final String FAKE_DATE
See Also:
Constant Field Values

dateStart

private final int dateStart

dateEnd

private final int dateEnd

usecStart

private final int usecStart

usecEnd

private final int usecEnd

LEVEL_KW

public static final String LEVEL_KW
See Also:
Constant Field Values

DIGIT

private static final char[] DIGIT

escape

private static Escape escape
Constructor Detail

EventLogMessage

protected EventLogMessage(String eventName)
Create a new LogMessage at the current time with a given event name. The timestamp is set at creation time, but can be changed later with setTimeStampMillis or setTimeStampNanos.

Parameters:
eventName - Name of this logging event.
See Also:
setTimeStampMillis(long), setTimeStampNanos(long)
Method Detail

add

public EventLogMessage add(String key,
                           String value)
Add a string.

Returns:
Self-reference, so calls can be chained

addWQ

public EventLogMessage addWQ(String key,
                             String value)
Add a string. Strings automatically have quotes around them and are escaped

Returns:
Self-reference, so calls can be chained

add

public EventLogMessage add(String key,
                           int value)
Add an int.

Returns:
Self-reference, so calls can be chained

add

public EventLogMessage add(String key,
                           long value)
Add a long.

Returns:
Self-reference, so calls can be chained

add

public EventLogMessage add(String key,
                           float value)
Add a float.

Returns:
Self-reference, so calls can be chained

add

public EventLogMessage add(String key,
                           double value)
Add a double.

Returns:
Self-reference, so calls can be chained

addPair

public EventLogMessage addPair(String key,
                               String pairKey,
                               String pairValue)
Add a key,value pair The result looks like: key = (pairKey, pairValue)

Parameters:
key -
pairKey -
pairValue -

addTime

public EventLogMessage addTime(String key,
                               long timeInMillis)

addMap

public EventLogMessage addMap(String key,
                              Map map)
Add a Map to the buffer. Represents maps as a series of (key, value) in quotes. The method assumes that both keys and values toString method returns a "nice" string representation. The method escapes all quotes

Parameters:
key -
map -
Returns:

addList

public EventLogMessage addList(String key,
                               List list)

addMsg

public EventLogMessage addMsg(String msg)
Add an natural language message to the log message. The string is put in quotes and is escaped

Parameters:
msg -
Returns:

setTimeStampMillis

public EventLogMessage setTimeStampMillis(long millis)
Set the timestamp from milliseconds returned by System.currentTimeMillis().

Returns:
'this' so we can chain

setTimeStampNanos

public EventLogMessage setTimeStampNanos(long nano1)
Set the timestamp from nanoseconds returned by System.nanoTime().

Returns:
'this' so we can chain

toString

public String toString()
Format a message in CEDPS Best Practices format.

Overrides:
toString in class Object
Returns:
Formatted message string
See Also:
CEDPS "Best Practices" format

addTimeStamp

private void addTimeStamp()
Add a timestamp to the message.



Copyright © 2011 The University of Southern California. All Rights Reserved.