Class Log


  • public class Log
    extends java.lang.Object
    Aether Logger - The main facade for managing the logging stack and proxying log calls.

    This class manages:

    • The ThreadLocal stack of LNodes (push, pop, get).
    • The global EventConsumer (fire, addListener).
    • Static proxy methods (info, warn, of) that delegate calls to the current LNode on top of the stack (Log.get()).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Log.Level
      Defines the standard logging levels.
      static interface  Log.LogAutoClose
      An AutoCloseable interface for managing logging contexts.
      static interface  Log.Tag
      An annotation for tagging loggers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.text.DateFormat DATE_FORMAT
      The default date format for printing timestamps.
      static boolean ENABLED
      Global enable/disable switch for the entire logging system.
      static java.lang.String EXCEPTION_STR
      Standard key for exceptions.
      static LogFilter filter
      The global filter for all log messages.
      static java.util.concurrent.atomic.AtomicLong ID_COUNTER
      A global, atomic counter for generating unique LNode IDs.
      static java.lang.String LEVEL
      Standard key for the log level.
      static java.lang.String MSG
      Standard key for the log message.
      static EventConsumer<LNode> onEvent
      The central event bus for all log records.
      static java.lang.ThreadLocal<java.util.Deque<LNode>> stack
      The thread-local stack of logging contexts (LNodes).
      static java.lang.String SYSTEM_COMPONENT
      Standard key for the system component.
      static java.lang.String TIME
      Standard key for the log timestamp.
      static boolean TRACE
      Enables or disables TRACE level logging globally.
    • Constructor Summary

      Constructors 
      Constructor Description
      Log()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addFilter​(APredicate<LNode> p)
      Adds a standard predicate to the global filter.
      static void addFilterNot​(APredicate<LNode> p)
      Adds a "NOT" predicate to the global filter.
      static java.lang.AutoCloseable addListener​(LogFilter filter, AConsumer<LNode> consumer)
      Adds a listener for log events, with a specific filter.
      static LNode debug​(ToString msg, java.lang.Object... data)
      Logs a DEBUG level message.
      static LNode debug​(java.lang.String msg, LNode data)
      Logs a DEBUG level message.
      static LNode debug​(java.lang.String msg, LNode... data)
      Logs a DEBUG level message.
      static LNode debug​(java.lang.String msg, java.lang.Object... data)
      Logs a DEBUG level message.
      static LNode error​(java.lang.String msg, java.lang.Object... data)
      Logs an ERROR level message.
      static LNode error​(java.lang.String msg, java.lang.Throwable throwable, java.lang.Object... data)
      Logs an ERROR level message with a throwable.
      static LNode error​(java.lang.Throwable throwable, java.lang.Object... data)
      Logs an ERROR level message from a throwable.
      static void fire​(LNode node)
      Centralized method to dispatch a log event.
      static LNode get()
      Gets the LNode from the top of the stack (O(1) complexity).
      static LNode info​(ToString msg, java.lang.Object... data)
      Logs an INFO level message.
      static LNode info​(java.lang.String msg, LNode data)
      Logs an INFO level message.
      static LNode info​(java.lang.String msg, LNode... data)
      Logs an INFO level message.
      static LNode info​(java.lang.String msg, java.lang.Object... data)
      Logs an INFO level message.
      static void log​(LNode node)
      Logs a custom LNode, using the current context as its parent.
      static void loggerOff()
      Disables all logging globally.
      static void loggerOn()
      Enables all logging globally.
      static LNode of()
      Returns the current LNode from the top of the stack.
      static LNode of​(LNode data)
      Creates a composite LNode, using the current stack node as its parent.
      static LNode of​(LNode... data)
      Creates a composite LNode, using the current stack node as its parent.
      static LNode of​(java.lang.Object... data)
      Creates a new LNode from key-value pairs, using the current stack node as its parent.
      static LNode of2​(java.lang.String[] keys, java.lang.Object[] vals)
      Creates a new LNode from key and value arrays, using the current stack node as its parent.
      static LNode ofMap​(java.util.Map<java.lang.String,​?> vals)
      Creates a new LNode from a Map, using the current stack node as its parent.
      static void pop​(LNode n)
      Pops a node from the current thread's context stack (O(1) complexity).
      static LogPrinter printConsoleColored()
      Creates a colored console printer with a default filter.
      static LogPrinter printConsoleColored​(LogFilter filter)
      Creates a colored console printer with a custom filter.
      static LogPrinter printPlainConsole​(LogFilter filter)
      Creates a plain console printer with a custom filter.
      static void push​(LNode n)
      Pushes a new node onto the current thread's context stack.
      static LNode trace​(ToString msg, java.lang.Object... data)
      Logs a TRACE level message.
      static LNode trace​(java.lang.String msg, LNode data)
      Logs a TRACE level message.
      static LNode trace​(java.lang.String msg, LNode... data)
      Logs a TRACE level message.
      static LNode trace​(java.lang.String msg, java.lang.Object... data)
      Logs a TRACE level message.
      static LNode warn​(ToString msg, java.lang.Object... data)
      Logs a WARN level message.
      static LNode warn​(java.lang.String msg, LNode data)
      Logs a WARN level message.
      static LNode warn​(java.lang.String msg, LNode... data)
      Logs a WARN level message.
      static LNode warn​(java.lang.String msg, java.lang.Object... data)
      Logs a WARN level message.
      static LNode warn​(java.lang.String msg, java.lang.Throwable throwable, java.lang.Object... data)
      Logs a WARN level message with a throwable.
      static <T,​T2>
      ABiConsumer<T,​T2>
      wrap​(ABiConsumer<T,​T2> t)
      Wraps a BiConsumer with the current logging context.
      static <T> AConsumer<T> wrap​(AConsumer<T> t)
      Wraps a Consumer with the current logging context.
      static <T,​R>
      AFunction<T,​R>
      wrap​(AFunction<T,​R> t)
      Wraps a Function with the current logging context.
      static ARunnable wrap​(ARunnable t)
      Wraps a Runnable with the current logging context.
      static <T> ASupplier<T> wrap​(ASupplier<T> t)
      Wraps a Supplier with the current logging context.
      static java.util.concurrent.Executor wrapExecutor​(java.util.concurrent.Executor executor)
      Wraps an Executor to preserve the logging context in executed tasks.
      static ARunnable wrapRunnable​(ARunnable t, java.lang.Object... data)
      Wraps a Runnable with a new logging context.
      static <T> ASupplier<T> wrapSupplier​(ASupplier<T> t)
      Wraps a Supplier with the current logging context.
      • Methods inherited from class java.lang.Object

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

      • TRACE

        public static final boolean TRACE
        Enables or disables TRACE level logging globally.
        See Also:
        Constant Field Values
      • TIME

        public static final java.lang.String TIME
        Standard key for the log timestamp.
        See Also:
        Constant Field Values
      • LEVEL

        public static final java.lang.String LEVEL
        Standard key for the log level.
        See Also:
        Constant Field Values
      • SYSTEM_COMPONENT

        public static final java.lang.String SYSTEM_COMPONENT
        Standard key for the system component.
        See Also:
        Constant Field Values
      • MSG

        public static final java.lang.String MSG
        Standard key for the log message.
        See Also:
        Constant Field Values
      • EXCEPTION_STR

        public static final java.lang.String EXCEPTION_STR
        Standard key for exceptions.
        See Also:
        Constant Field Values
      • filter

        public static final LogFilter filter
        The global filter for all log messages.
      • DATE_FORMAT

        public static final java.text.DateFormat DATE_FORMAT
        The default date format for printing timestamps.
      • ENABLED

        public static boolean ENABLED
        Global enable/disable switch for the entire logging system.
      • stack

        public static final java.lang.ThreadLocal<java.util.Deque<LNode>> stack
        The thread-local stack of logging contexts (LNodes).
      • ID_COUNTER

        public static final java.util.concurrent.atomic.AtomicLong ID_COUNTER
        A global, atomic counter for generating unique LNode IDs.
      • onEvent

        public static final EventConsumer<LNode> onEvent
        The central event bus for all log records.
    • Constructor Detail

      • Log

        public Log()
    • Method Detail

      • push

        public static void push​(LNode n)
        Pushes a new node onto the current thread's context stack.
        Parameters:
        n - The LNode to push.
      • get

        public static LNode get()
        Gets the LNode from the top of the stack (O(1) complexity).
        Returns:
        The current LNode, or LNode.EMPTY if the stack is empty.
      • pop

        public static void pop​(LNode n)
        Pops a node from the current thread's context stack (O(1) complexity).
        Parameters:
        n - The expected node to pop (used for validation).
        Throws:
        java.lang.IllegalStateException - if the stack is empty or the wrong node is popped.
      • fire

        public static void fire​(LNode node)
        Centralized method to dispatch a log event. This applies the global filter and fires an event on the main event bus.
        Parameters:
        node - The LNode to fire.
      • addListener

        public static java.lang.AutoCloseable addListener​(LogFilter filter,
                                                          AConsumer<LNode> consumer)
        Adds a listener for log events, with a specific filter.
        Parameters:
        filter - The filter to apply for this listener.
        consumer - The consumer that will receive filtered log nodes.
        Returns:
        An AutoCloseable that can be used to remove the listener.
      • addFilterNot

        public static void addFilterNot​(APredicate<LNode> p)
        Adds a "NOT" predicate to the global filter.
        Parameters:
        p - The predicate to apply.
      • addFilter

        public static void addFilter​(APredicate<LNode> p)
        Adds a standard predicate to the global filter.
        Parameters:
        p - The predicate to apply.
      • log

        public static void log​(LNode node)
        Logs a custom LNode, using the current context as its parent.
        Parameters:
        node - The LNode to log.
      • trace

        public static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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.
      • of

        public static LNode of​(java.lang.Object... data)
        Creates a new LNode from key-value pairs, 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 composite LNode, using the current stack node as its parent.
        Parameters:
        data - The LNode to compose.
        Returns:
        The new LNode.
      • of

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

        public static LNode ofMap​(java.util.Map<java.lang.String,​?> vals)
        Creates a new LNode from a Map, using the current stack node as its parent.
        Parameters:
        vals - 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 key and value arrays, using the current stack node as its parent.
        Parameters:
        keys - The array of keys.
        vals - The array of values.
        Returns:
        The new LNode.
      • of

        public static LNode of()
        Returns the current LNode from the top of the stack.
        Returns:
        The current LNode.
      • printConsoleColored

        public static LogPrinter printConsoleColored()
        Creates a colored console printer with a default filter.
        Returns:
        A LogPrinter instance.
      • printConsoleColored

        public static LogPrinter printConsoleColored​(LogFilter filter)
        Creates a colored console printer with a custom filter.
        Parameters:
        filter - The custom filter for the printer.
        Returns:
        A LogPrinter instance.
      • printPlainConsole

        public static LogPrinter printPlainConsole​(LogFilter filter)
        Creates a plain console printer with a custom filter.
        Parameters:
        filter - The custom filter for the printer.
        Returns:
        A LogPrinter instance.
      • wrapExecutor

        public static java.util.concurrent.Executor wrapExecutor​(java.util.concurrent.Executor executor)
        Wraps an Executor to preserve the logging context in executed tasks.
        Parameters:
        executor - The original executor.
        Returns:
        A wrapped Executor.
      • wrapRunnable

        public static ARunnable wrapRunnable​(ARunnable t,
                                             java.lang.Object... data)
        Wraps a Runnable with a new logging context.
        Parameters:
        t - The Runnable to wrap.
        data - The context data for the wrapper.
        Returns:
        A wrapped Runnable.
      • wrapSupplier

        public static <T> ASupplier<T> wrapSupplier​(ASupplier<T> t)
        Wraps a Supplier with the current logging context.
        Type Parameters:
        T - The return type of the supplier.
        Parameters:
        t - The Supplier to wrap.
        Returns:
        A wrapped Supplier.
      • wrap

        public static <T> ASupplier<T> wrap​(ASupplier<T> t)
        Wraps a Supplier with the current logging context.
        Type Parameters:
        T - The return type of the supplier.
        Parameters:
        t - The Supplier to wrap.
        Returns:
        A wrapped Supplier.
      • wrap

        public static ARunnable wrap​(ARunnable t)
        Wraps a Runnable with the current logging context.
        Parameters:
        t - The Runnable to wrap.
        Returns:
        A wrapped Runnable.
      • wrap

        public static <T> AConsumer<T> wrap​(AConsumer<T> t)
        Wraps a Consumer with the current logging context.
        Type Parameters:
        T - The type of the consumer.
        Parameters:
        t - The Consumer to wrap.
        Returns:
        A wrapped Consumer.
      • wrap

        public static <T,​T2> ABiConsumer<T,​T2> wrap​(ABiConsumer<T,​T2> t)
        Wraps a BiConsumer with the current logging context.
        Type Parameters:
        T - The first type of the consumer.
        T2 - The second type of the consumer.
        Parameters:
        t - The BiConsumer to wrap.
        Returns:
        A wrapped BiConsumer.
      • wrap

        public static <T,​R> AFunction<T,​R> wrap​(AFunction<T,​R> t)
        Wraps a Function with the current logging context.
        Type Parameters:
        T - The input type of the function.
        R - The return type of the function.
        Parameters:
        t - The Function to wrap.
        Returns:
        A wrapped Function.
      • loggerOff

        public static void loggerOff()
        Disables all logging globally.
      • loggerOn

        public static void loggerOn()
        Enables all logging globally.