Class LNode

  • All Implemented Interfaces:
    ToString

    public abstract class LNode
    extends java.lang.Object
    implements ToString
    A logging node (LNode) represents a piece of context or a log message. It is structured as a single-linked list (via the 'parent' field).

    This class now contains instance methods (info, warn, etc.) that create new log nodes, using this instance as the parent.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  LNode.AutoCloseable
      Defines an AutoCloseable context for this LNode.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static LNode EMPTY
      A global, shared, immutable empty LNode.
      long id
      The unique ID for this node, sourced from the global counter in Log.
      LNode parent
      The parent node in the single-linked list.
    • Constructor Summary

      Constructors 
      Constructor Description
      LNode​(LNode parent)
      Constructs a new LNode with a given parent.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      LNode add​(LNode data)
      Creates a new composite LNode with this as its parent.
      LNode add​(LNode... data)
      Creates a new composite LNode with this as its parent.
      LNode add​(java.lang.Object... data)
      Creates a new LNode (from key-value pairs) with this as its parent.
      LNode add​(java.lang.String[] keys, java.lang.Object[] vals)
      Creates a new LNode (from arrays) with this as its parent.
      LNode addMap​(java.util.Map<java.lang.String,​?> vals)
      Creates a new LNode (from a Map) with this as its parent.
      boolean check​(java.lang.String key, java.lang.Object value)
      Checks if a key's value equals a specific value.
      boolean checkSystemComponent​(java.lang.Object val)
      Checks if the system component equals a specific value.
      boolean contains​(java.lang.String key)
      Checks if a key exists in this node or its parents.
      LNode.AutoCloseable context()
      Pushes this node onto the stack and returns an AutoCloseable that will pop it off when closed.
      int count()
      Counts all key-value pairs, recursively searching parents.
      protected abstract int count0()
      Abstract method to count key-value pairs *in this node only*.
      LNode debug​(ToString msg, java.lang.Object... data)
      Logs a DEBUG level message.
      LNode debug​(java.lang.String msg, LNode data)
      Logs a DEBUG level message.
      LNode debug​(java.lang.String msg, LNode... data)
      Logs a DEBUG level message.
      LNode debug​(java.lang.String msg, java.lang.Object... data)
      Logs a DEBUG level message.
      LNode error​(java.lang.String msg, java.lang.Object... data)
      Logs an ERROR level message.
      LNode error​(java.lang.String msg, java.lang.Throwable throwable, java.lang.Object... data)
      Logs an ERROR level message with a throwable.
      LNode error​(java.lang.Throwable throwable, java.lang.Object... data)
      Logs an ERROR level message from a throwable.
      void foreach​(java.util.Set<java.lang.String> exclude, ABiConsumer<java.lang.String,​java.lang.Object> c)
      Iterates over all key-value pairs, recursively searching parents.
      protected abstract void foreach0​(java.util.Set<java.lang.String> exclude, ABiConsumer<java.lang.String,​java.lang.Object> c)
      Abstract method to iterate over key-value pairs *in this node only*.
      <T> T get​(java.lang.String key)
      Gets a value for a key, recursively searching parents.
      protected abstract java.lang.Object get0​(java.lang.String key)
      Abstract method to get a value for a key from *this node only*.
      <T> T getCast​(java.lang.String key)
      Gets a value and casts it.
      java.lang.Throwable getException()
      Gets the exception (Log.EXCEPTION_STR) from this node.
      Log.Level getLevel()
      Gets the log level (Log.LEVEL).
      AString getMessage()
      Gets the formatted log message.
      AString getMessage​(java.util.Set<java.lang.String> keys)
      Gets the formatted log message.
      java.lang.String getMsg()
      Gets the log message (Log.MSG).
      java.lang.Object getSystemComponent()
      Gets the system component (Log.SYSTEM_COMPONENT).
      LNode info​(ToString msg, java.lang.Object... data)
      Logs an INFO level message.
      LNode info​(java.lang.String msg, LNode data)
      Logs an INFO level message.
      LNode info​(java.lang.String msg, LNode... data)
      Logs an INFO level message.
      LNode info​(java.lang.String msg, java.lang.Object... data)
      Logs an INFO level message.
      boolean isDebug()
      Checks if the log level is DEBUG.
      boolean isEmpty()
      Checks if the node and its parents are empty.
      boolean isError()
      Checks if the log level is ERROR.
      boolean isInfo()
      Checks if the log level is INFO.
      boolean isTrace()
      Checks if the log level is TRACE.
      boolean isWarn()
      Checks if the log level is WARN.
      void log​(LNode node)
      Logs a custom LNode, firing it to the event bus.
      boolean msgContains​(java.lang.String testData)  
      static LNode of​(LNode... data)
      Creates a new composite LNode using the current stack node as its parent.
      static LNode of​(java.lang.Object... data)
      Creates a new LNode using the current stack node as its parent.
      static LNode of2​(LNode parent, LNode... data)
      Factory method to create a composite LNode.
      static LNode of2​(LNode parent, java.lang.Object... data)
      Factory method to create an LNode from key-value pairs.
      static LNode of2​(LNode parent, java.lang.String[] keys, java.lang.Object[] vals)
      Factory method to create an LNode from key and value arrays.
      static LNode of2​(java.lang.String[] keys, java.lang.Object[] vals)
      Creates a new LNode from arrays using the current stack node as its parent.
      static LNode ofMap​(LNode parent, java.util.Map<java.lang.String,​?> map)
      Factory method to create an LNode from a Map.
      static LNode ofMap​(java.util.Map<java.lang.String,​?> map)
      Creates a new LNode from a Map using the current stack node as its parent.
      void printMessage​(AString w, java.util.Set<java.lang.String> keys, java.lang.String color, java.lang.String defaultColor)
      Appends the formatted log message to an AString builder.
      java.util.Map<java.lang.String,​java.lang.Object> toMap()
      Converts the node and all its parents into a Map.
      java.lang.String toString()
      Returns a string representation of this node.
      void toString​(AString sb)
      Appends a string representation of this node to an AString builder.
      LNode trace​(ToString msg, java.lang.Object... data)
      Logs a TRACE level message.
      LNode trace​(java.lang.String msg, LNode data)
      Logs a TRACE level message.
      LNode trace​(java.lang.String msg, LNode... data)
      Logs a TRACE level message.
      LNode trace​(java.lang.String msg, java.lang.Object... data)
      Logs a TRACE level message.
      LNode warn​(ToString msg, java.lang.Object... data)
      Logs a WARN level message.
      LNode warn​(java.lang.String msg, LNode data)
      Logs a WARN level message.
      LNode warn​(java.lang.String msg, LNode... data)
      Logs a WARN level message.
      LNode warn​(java.lang.String msg, java.lang.Object... data)
      Logs a WARN level message.
      LNode warn​(java.lang.String msg, java.lang.Throwable throwable, java.lang.Object... data)
      Logs a WARN level message with a throwable.
      • Methods inherited from class java.lang.Object

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

      • id

        public final long id
        The unique ID for this node, sourced from the global counter in Log.
      • EMPTY

        public static final LNode EMPTY
        A global, shared, immutable empty LNode. It overrides all logging and add methods to do nothing.
      • parent

        public final LNode parent
        The parent node in the single-linked list.
    • Constructor Detail

      • LNode

        public LNode​(LNode parent)
        Constructs a new LNode with a given parent.
        Parameters:
        parent - The parent node.
    • Method Detail

      • msgContains

        public boolean msgContains​(java.lang.String testData)
      • add

        public LNode add​(java.lang.Object... data)
        Creates a new LNode (from key-value pairs) with this as its parent.
        Parameters:
        data - Alternating key-value pairs.
        Returns:
        The new LNode.
      • add

        public LNode add​(LNode data)
        Creates a new composite LNode with this as its parent.
        Parameters:
        data - The node to compose.
        Returns:
        The new LNode.
      • add

        public LNode add​(LNode... data)
        Creates a new composite LNode with this as its parent.
        Parameters:
        data - The nodes to compose.
        Returns:
        The new LNode.
      • addMap

        public LNode addMap​(java.util.Map<java.lang.String,​?> vals)
        Creates a new LNode (from a Map) with this as its parent.
        Parameters:
        vals - The Map of key-value pairs.
        Returns:
        The new LNode.
      • add

        public LNode add​(java.lang.String[] keys,
                         java.lang.Object[] vals)
        Creates a new LNode (from arrays) with this as its parent.
        Parameters:
        keys - The array of keys.
        vals - The array of values.
        Returns:
        The new LNode.
      • context

        public LNode.AutoCloseable context()
        Pushes this node onto the stack and returns an AutoCloseable that will pop it off when closed.
        Returns:
        An AutoCloseable context.
      • toString

        public void toString​(AString sb)
        Appends a string representation of this node to an AString builder.
        Specified by:
        toString in interface ToString
        Parameters:
        sb - The AString builder.
      • get0

        protected abstract java.lang.Object get0​(java.lang.String key)
        Abstract method to get a value for a key from *this node only*.
        Parameters:
        key - The key to look up.
        Returns:
        The value, or null if not found.
      • get

        public final <T> T get​(java.lang.String key)
        Gets a value for a key, recursively searching parents.
        Type Parameters:
        T - The expected type of the value.
        Parameters:
        key - The key to look up.
        Returns:
        The value, or null if not found.
      • foreach0

        protected abstract void foreach0​(java.util.Set<java.lang.String> exclude,
                                         ABiConsumer<java.lang.String,​java.lang.Object> c)
        Abstract method to iterate over key-value pairs *in this node only*.
        Parameters:
        exclude - A set of keys to exclude.
        c - The consumer to accept key-value pairs.
      • foreach

        public void foreach​(java.util.Set<java.lang.String> exclude,
                            ABiConsumer<java.lang.String,​java.lang.Object> c)
        Iterates over all key-value pairs, recursively searching parents.
        Parameters:
        exclude - A set of keys to exclude.
        c - The consumer to accept key-value pairs.
      • count0

        protected abstract int count0()
        Abstract method to count key-value pairs *in this node only*.
        Returns:
        The count of pairs.
      • count

        public int count()
        Counts all key-value pairs, recursively searching parents.
        Returns:
        The total count of unique pairs.
      • isEmpty

        public boolean isEmpty()
        Checks if the node and its parents are empty.
        Returns:
        true if count() is 0.
      • toString

        public java.lang.String toString()
        Returns a string representation of this node.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation.
      • toMap

        public java.util.Map<java.lang.String,​java.lang.Object> toMap()
        Converts the node and all its parents into a Map.
        Returns:
        A Map containing all key-value pairs.
      • getCast

        public <T> T getCast​(java.lang.String key)
        Gets a value and casts it.
        Type Parameters:
        T - The expected type.
        Parameters:
        key - The key to look up.
        Returns:
        The casted value, or null.
      • contains

        public boolean contains​(java.lang.String key)
        Checks if a key exists in this node or its parents.
        Parameters:
        key - The key to check.
        Returns:
        true if the key exists.
      • getMsg

        public java.lang.String getMsg()
        Gets the log message (Log.MSG).
        Returns:
        The message string, or null.
      • getMessage

        public AString getMessage()
        Gets the formatted log message.
        Returns:
        The formatted message as an AString.
      • getMessage

        public AString getMessage​(java.util.Set<java.lang.String> keys)
        Gets the formatted log message.
        Parameters:
        keys - A set of keys to exclude.
        Returns:
        The formatted message as an AString.
      • printMessage

        public void printMessage​(AString w,
                                 java.util.Set<java.lang.String> keys,
                                 java.lang.String color,
                                 java.lang.String defaultColor)
        Appends the formatted log message to an AString builder.
        Parameters:
        w - The AString builder.
        keys - A set of keys to exclude.
        color - A color string.
        defaultColor - A default color string.
      • getSystemComponent

        public java.lang.Object getSystemComponent()
        Gets the system component (Log.SYSTEM_COMPONENT).
        Returns:
        The system component object.
      • checkSystemComponent

        public boolean checkSystemComponent​(java.lang.Object val)
        Checks if the system component equals a specific value.
        Parameters:
        val - The value to check against.
        Returns:
        true if equal.
      • isTrace

        public boolean isTrace()
        Checks if the log level is TRACE.
        Returns:
        true if TRACE.
      • isDebug

        public boolean isDebug()
        Checks if the log level is DEBUG.
        Returns:
        true if DEBUG.
      • isInfo

        public boolean isInfo()
        Checks if the log level is INFO.
        Returns:
        true if INFO.
      • isWarn

        public boolean isWarn()
        Checks if the log level is WARN.
        Returns:
        true if WARN.
      • isError

        public boolean isError()
        Checks if the log level is ERROR.
        Returns:
        true if ERROR.
      • check

        public boolean check​(java.lang.String key,
                             java.lang.Object value)
        Checks if a key's value equals a specific value.
        Parameters:
        key - The key to check.
        value - The value to check against.
        Returns:
        true if equal.
      • getException

        public java.lang.Throwable getException()
        Gets the exception (Log.EXCEPTION_STR) from this node.
        Returns:
        The Throwable, or null.
      • getLevel

        public Log.Level getLevel()
        Gets the log level (Log.LEVEL).
        Returns:
        The Log.Level enum, or null.
      • log

        public void log​(LNode node)
        Logs a custom LNode, firing it to the event bus.
        Parameters:
        node - The node to log.
      • trace

        public LNode trace​(ToString msg,
                           java.lang.Object... data)
        Logs a TRACE level message.
        Parameters:
        msg - The message object.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • trace

        public LNode trace​(java.lang.String msg,
                           LNode... data)
        Logs a TRACE level message.
        Parameters:
        msg - The message string.
        data - Additional LNodes.
        Returns:
        The created LNode.
      • trace

        public LNode trace​(java.lang.String msg,
                           LNode data)
        Logs a TRACE level message.
        Parameters:
        msg - The message string.
        data - An additional LNode.
        Returns:
        The created LNode.
      • trace

        public LNode trace​(java.lang.String msg,
                           java.lang.Object... data)
        Logs a TRACE level message.
        Parameters:
        msg - The message string.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • debug

        public LNode debug​(ToString msg,
                           java.lang.Object... data)
        Logs a DEBUG level message.
        Parameters:
        msg - The message object.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • debug

        public LNode debug​(java.lang.String msg,
                           java.lang.Object... data)
        Logs a DEBUG level message.
        Parameters:
        msg - The message string.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • debug

        public LNode debug​(java.lang.String msg,
                           LNode... data)
        Logs a DEBUG level message.
        Parameters:
        msg - The message string.
        data - Additional LNodes.
        Returns:
        The created LNode.
      • debug

        public LNode debug​(java.lang.String msg,
                           LNode data)
        Logs a DEBUG level message.
        Parameters:
        msg - The message string.
        data - An additional LNode.
        Returns:
        The created LNode.
      • info

        public LNode info​(ToString msg,
                          java.lang.Object... data)
        Logs an INFO level message.
        Parameters:
        msg - The message object.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • info

        public LNode info​(java.lang.String msg,
                          java.lang.Object... data)
        Logs an INFO level message.
        Parameters:
        msg - The message string.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • info

        public LNode info​(java.lang.String msg,
                          LNode... data)
        Logs an INFO level message.
        Parameters:
        msg - The message string.
        data - Additional LNodes.
        Returns:
        The created LNode.
      • info

        public LNode info​(java.lang.String msg,
                          LNode data)
        Logs an INFO level message.
        Parameters:
        msg - The message string.
        data - An additional LNode.
        Returns:
        The created LNode.
      • warn

        public LNode warn​(ToString msg,
                          java.lang.Object... data)
        Logs a WARN level message.
        Parameters:
        msg - The message object.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • warn

        public LNode warn​(java.lang.String msg,
                          java.lang.Object... data)
        Logs a WARN level message.
        Parameters:
        msg - The message string.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • warn

        public LNode warn​(java.lang.String msg,
                          LNode... data)
        Logs a WARN level message.
        Parameters:
        msg - The message string.
        data - Additional LNodes.
        Returns:
        The created LNode.
      • warn

        public LNode warn​(java.lang.String msg,
                          LNode data)
        Logs a WARN level message.
        Parameters:
        msg - The message string.
        data - An additional LNode.
        Returns:
        The created LNode.
      • warn

        public LNode warn​(java.lang.String msg,
                          java.lang.Throwable throwable,
                          java.lang.Object... data)
        Logs a WARN level message with a throwable.
        Parameters:
        msg - The message string.
        throwable - The exception to log.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • error

        public LNode error​(java.lang.String msg,
                           java.lang.Throwable throwable,
                           java.lang.Object... data)
        Logs an ERROR level message with a throwable.
        Parameters:
        msg - The message string.
        throwable - The exception to log.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • error

        public LNode error​(java.lang.String msg,
                           java.lang.Object... data)
        Logs an ERROR level message.
        Parameters:
        msg - The message string.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • error

        public LNode error​(java.lang.Throwable throwable,
                           java.lang.Object... data)
        Logs an ERROR level message from a throwable.
        Parameters:
        throwable - The exception to log.
        data - Additional key-value pairs.
        Returns:
        The created LNode.
      • of2

        public static LNode of2​(LNode parent,
                                LNode... data)
        Factory method to create a composite LNode.
        Parameters:
        parent - The parent node.
        data - The child nodes to compose.
        Returns:
        The new LNode.
      • of2

        public static LNode of2​(LNode parent,
                                java.lang.Object... data)
        Factory method to create an LNode from key-value pairs.
        Parameters:
        parent - The parent node.
        data - Alternating key-value pairs.
        Returns:
        The new LNode.
      • ofMap

        public static LNode ofMap​(LNode parent,
                                  java.util.Map<java.lang.String,​?> map)
        Factory method to create an LNode from a Map.
        Parameters:
        parent - The parent node.
        map - The Map of key-value pairs.
        Returns:
        The new LNode.
      • of2

        public static LNode of2​(LNode parent,
                                java.lang.String[] keys,
                                java.lang.Object[] vals)
        Factory method to create an LNode from key and value arrays.
        Parameters:
        parent - The parent node.
        keys - The array of keys.
        vals - The array of values.
        Returns:
        The new LNode.
      • of

        public static LNode of​(java.lang.Object... data)
        Creates a new LNode using the current stack node as its parent.
        Parameters:
        data - Alternating key-value pairs.
        Returns:
        The new LNode.
      • of

        public static LNode of​(LNode... data)
        Creates a new composite LNode using the current stack node as its parent.
        Parameters:
        data - The child nodes to compose.
        Returns:
        The new LNode.
      • ofMap

        public static LNode ofMap​(java.util.Map<java.lang.String,​?> map)
        Creates a new LNode from a Map using the current stack node as its parent.
        Parameters:
        map - The Map of key-value pairs.
        Returns:
        The new LNode.
      • of2

        public static LNode of2​(java.lang.String[] keys,
                                java.lang.Object[] vals)
        Creates a new LNode from arrays using the current stack node as its parent.
        Parameters:
        keys - The array of keys.
        vals - The array of values.
        Returns:
        The new LNode.