Class Trace


  • public class Trace
    extends java.lang.Object
    A Trace object contains ad-hoc string notes organized in a strict-loose tree. A Trace object consists of a trace level indicating which trace notes should be included and a TraceTree object containing the tree structure and collecting the trace information. Tracing is used to collect debug information about a Routable traveling through the system. The trace level is in the range [0,9]. 0 means no tracing, and 9 means all tracing is enabled. A client that has the ability to trace information will have a predefined level attached to that information. If the level on the information is lower or equal to the level set in the Trace object, the information will be traced.
    Author:
    Simon Thoresen Hult
    • Constructor Summary

      Constructors 
      Constructor Description
      Trace()
      Create an empty trace with level set to 0 (no tracing)
      Trace​(int level)
      Create an empty trace with given level.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Trace clear()
      Remove all trace information and set the trace level to 0.
      int getLevel()
      Returns the trace level.
      TraceNode getRoot()
      Returns the root of the trace tree.
      Trace setLevel​(int level)
      Set the trace level.
      boolean shouldTrace​(int level)
      Check if information with the given level should be traced.
      Trace swap​(Trace other)
      Swap the internals of this with another.
      java.lang.String toString()  
      boolean trace​(int level, java.lang.String note)
      Add the given note to the trace information if tracing is enabled for the given level.
      boolean trace​(int level, java.lang.String note, boolean addTime)
      Add the given note to the trace information if tracing is enabled for the given level.
      • Methods inherited from class java.lang.Object

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

      • Trace

        public Trace()
        Create an empty trace with level set to 0 (no tracing)
      • Trace

        public Trace​(int level)
        Create an empty trace with given level.
        Parameters:
        level - Level to set.
    • Method Detail

      • clear

        public Trace clear()
        Remove all trace information and set the trace level to 0.
        Returns:
        This, to allow chaining.
      • swap

        public Trace swap​(Trace other)
        Swap the internals of this with another.
        Parameters:
        other - The trace to swap internals with.
        Returns:
        This, to allow chaining.
      • setLevel

        public Trace setLevel​(int level)
        Set the trace level. 0 means no tracing, 9 means enable all tracing.
        Parameters:
        level - The level to set.
        Returns:
        This, to allow chaining.
      • getLevel

        public int getLevel()
        Returns the trace level.
        Returns:
        The trace level.
      • shouldTrace

        public boolean shouldTrace​(int level)
        Check if information with the given level should be traced. This method is added to allow clients to check if something should be traced before spending time building up the trace information itself.
        Parameters:
        level - The trace level to test.
        Returns:
        True if tracing is enabled for the given level, false otherwise.
      • trace

        public boolean trace​(int level,
                             java.lang.String note)
        Add the given note to the trace information if tracing is enabled for the given level.
        Parameters:
        level - The trace level of the note.
        note - The note to add.
        Returns:
        True if the note was added to the trace information, false otherwise.
      • trace

        public boolean trace​(int level,
                             java.lang.String note,
                             boolean addTime)
        Add the given note to the trace information if tracing is enabled for the given level. If the addTime parameter is true, then the note is prefixed with the current time. This is the default behaviour when ommiting this parameter.
        Parameters:
        level - The trace level of the note.
        note - The note to add.
        addTime - Whether or not to prefix note with a timestamp.
        Returns:
        True if the note was added to the trace information, false otherwise.
      • getRoot

        public TraceNode getRoot()
        Returns the root of the trace tree.
        Returns:
        The root.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object