Class LogNode


  • public class LogNode
    extends java.lang.Object
    A tree-structured threadsafe log that allows you to add log entries in arbitrary order, and have the output retain a sane order. The order may also be made deterministic by specifying a sort key for log entries.
    • Constructor Summary

      Constructors 
      Constructor Description
      LogNode()
      Create a toplevel log node.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addElapsedTime()
      Call this once the work corresponding with a given log entry has completed if you want to show the time taken after the log entry.
      void flush()
      Flush out the log to stderr, and clear the log contents.
      LogNode log​(java.lang.String msg)
      Add a log entry.
      LogNode log​(java.lang.String msg, long elapsedTimeNanos)
      Add a log entry.
      LogNode log​(java.lang.String msg, long elapsedTimeNanos, java.lang.Throwable e)
      Add a log entry.
      LogNode log​(java.lang.String sortKey, java.lang.String msg)
      Add a log entry with sort key for deterministic ordering.
      LogNode log​(java.lang.String sortKey, java.lang.String msg, long elapsedTimeNanos)
      Add a log entry with sort key for deterministic ordering.
      LogNode log​(java.lang.String sortKey, java.lang.String msg, long elapsedTimeNanos, java.lang.Throwable e)
      Add a log entry with sort key for deterministic ordering.
      LogNode log​(java.lang.String sortKey, java.lang.String msg, java.lang.Throwable e)
      Add a log entry with sort key for deterministic ordering.
      LogNode log​(java.lang.String msg, java.lang.Throwable e)
      Add a log entry.
      LogNode log​(java.lang.Throwable e)
      Add a log entry.
      LogNode log​(java.util.Collection<java.lang.String> msgs)
      Add a series of log entries.
      static void logInRealtime​(boolean logInRealtime)
      If logInRealtime is true, log entries are output in realtime, as well as added to the LogNode tree.
      java.lang.String toString()
      Build the log output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LogNode

        public LogNode()
        Create a toplevel log node.
    • Method Detail

      • logInRealtime

        public static void logInRealtime​(boolean logInRealtime)
        If logInRealtime is true, log entries are output in realtime, as well as added to the LogNode tree. This can help debug situations where log info is never shown, e.g. deadlocks, or where you need to show the log info right up to the point where you hit a breakpoint.
      • toString

        public java.lang.String toString()
        Build the log output. Call this on the toplevel log node.
        Overrides:
        toString in class java.lang.Object
      • addElapsedTime

        public void addElapsedTime()
        Call this once the work corresponding with a given log entry has completed if you want to show the time taken after the log entry.
      • log

        public LogNode log​(java.lang.String sortKey,
                           java.lang.String msg,
                           long elapsedTimeNanos,
                           java.lang.Throwable e)
        Add a log entry with sort key for deterministic ordering.
        Parameters:
        sortKey - The sort key for the log entry.
        msg - The message.
        elapsedTimeNanos - The elapsed time.
        e - The Throwable that was thrown.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String sortKey,
                           java.lang.String msg,
                           long elapsedTimeNanos)
        Add a log entry with sort key for deterministic ordering.
        Parameters:
        sortKey - The sort key for the log entry.
        msg - The message.
        elapsedTimeNanos - The elapsed time.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String sortKey,
                           java.lang.String msg,
                           java.lang.Throwable e)
        Add a log entry with sort key for deterministic ordering.
        Parameters:
        sortKey - The sort key for the log entry.
        msg - The message.
        e - The Throwable that was thrown.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String sortKey,
                           java.lang.String msg)
        Add a log entry with sort key for deterministic ordering.
        Parameters:
        sortKey - The sort key for the log entry.
        msg - The message.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String msg,
                           long elapsedTimeNanos,
                           java.lang.Throwable e)
        Add a log entry.
        Parameters:
        msg - The message.
        elapsedTimeNanos - The elapsed time.
        e - The Throwable that was thrown.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String msg,
                           long elapsedTimeNanos)
        Add a log entry.
        Parameters:
        msg - The message.
        elapsedTimeNanos - The elapsed time.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String msg,
                           java.lang.Throwable e)
        Add a log entry.
        Parameters:
        msg - The message.
        e - The Throwable that was thrown.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.String msg)
        Add a log entry.
        Parameters:
        msg - The message.
        Returns:
        a child log node, which can be used to add sub-entries.
      • log

        public LogNode log​(java.util.Collection<java.lang.String> msgs)
        Add a series of log entries. Returns the last LogNode created.
        Parameters:
        msgs - The messages.
        Returns:
        the last log node created, which can be used to add sub-entries.
      • log

        public LogNode log​(java.lang.Throwable e)
        Add a log entry.
        Parameters:
        e - The Throwable that was thrown.
        Returns:
        a child log node, which can be used to add sub-entries.
      • flush

        public void flush()
        Flush out the log to stderr, and clear the log contents. Only call this on the toplevel log node, when threads do not have access to references of internal log nodes so that they cannot add more log entries inside the tree, otherwise log entries may be lost.