Class EventLogMessage


  • public class EventLogMessage
    extends java.lang.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

      Nested Classes 
      Modifier and Type Class Description
      private static class  EventLogMessage.Log4jFilter
      In log4j, ignore all messages not specifically directed at this appender.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected EventLogMessage​(java.lang.String eventName)
      Create a new LogMessage at the current time with a given event name.
    • Field Detail

      • buf

        private final java.lang.StringBuffer buf
      • micro0

        private static long micro0
      • nano0

        private static long nano0
      • micro1

        private static long micro1
      • micro2

        private long micro2
      • timeString

        private static java.lang.String timeString
      • format

        private static java.text.SimpleDateFormat format
      • calendar

        private static final java.util.GregorianCalendar calendar
      • timeStringLock

        private static java.util.concurrent.locks.Lock timeStringLock
      • dateStart

        private final int dateStart
      • dateEnd

        private final int dateEnd
      • usecStart

        private final int usecStart
      • usecEnd

        private final int usecEnd
      • DIGIT

        private static final char[] DIGIT
      • escape

        private static Escape escape
    • Constructor Detail

      • EventLogMessage

        protected EventLogMessage​(java.lang.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​(java.lang.String key,
                                   java.lang.String value)
        Add a string.
        Returns:
        Self-reference, so calls can be chained
      • addWQ

        public EventLogMessage addWQ​(java.lang.String key,
                                     java.lang.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​(java.lang.String key,
                                   int value)
        Add an int.
        Returns:
        Self-reference, so calls can be chained
      • add

        public EventLogMessage add​(java.lang.String key,
                                   long value)
        Add a long.
        Returns:
        Self-reference, so calls can be chained
      • add

        public EventLogMessage add​(java.lang.String key,
                                   float value)
        Add a float.
        Returns:
        Self-reference, so calls can be chained
      • add

        public EventLogMessage add​(java.lang.String key,
                                   double value)
        Add a double.
        Returns:
        Self-reference, so calls can be chained
      • addPair

        public EventLogMessage addPair​(java.lang.String key,
                                       java.lang.String pairKey,
                                       java.lang.String pairValue)
        Add a key,value pair The result looks like: key = (pairKey, pairValue)
        Parameters:
        key -
        pairKey -
        pairValue -
      • addTime

        public EventLogMessage addTime​(java.lang.String key,
                                       long timeInMillis)
      • addMap

        public EventLogMessage addMap​(java.lang.String key,
                                      java.util.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​(java.lang.String key,
                                       java.util.List list)
      • addMsg

        public EventLogMessage addMsg​(java.lang.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 java.lang.String toString()
        Format a message in CEDPS Best Practices format.
        Overrides:
        toString in class java.lang.Object
        Returns:
        Formatted message string
        See Also:
        CEDPS "Best Practices" format
      • addTimeStamp

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