Package io.aether.logger
Class Log
- java.lang.Object
-
- io.aether.logger.Log
-
public class Log extends java.lang.ObjectAether Logger - powerful logging system with context support, filtering and formatting. Main features: - Logging with levels (TRACE, DEBUG, INFO, WARN, ERROR) - Contextual logging with automatic lifecycle management - Log filtering by various criteria - Colored console output support - Wrappers for code execution in logging context - Thread safety
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLog.LevelLog levelsstatic interfaceLog.LogAutoCloseAutoCloseable interface for logging contextsstatic interfaceLog.TagAnnotation for tagging loggers
-
Field Summary
Fields Modifier and Type Field Description static java.text.DateFormatDATE_FORMATstatic booleanENABLEDGlobal enabled/disabled state of the loggerstatic java.lang.StringEXCEPTION_STRstatic LogFilterfilterGlobal logger filter for all log messagesstatic java.lang.StringLEVELstatic java.lang.StringMSGstatic java.lang.StringSYSTEM_COMPONENTstatic java.lang.StringTIMEstatic booleanTRACE
-
Constructor Summary
Constructors Constructor Description Log()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddFilter(APredicate<LNode> p)Adds a positive filter (includes only logs that match the predicate)static voidaddFilterNot(APredicate<LNode> p)Adds a negative filter (excludes logs that match the predicate)static java.lang.AutoCloseableaddListener(LogFilter filter, AConsumer<LNode> consumer)Adds a listener for log events with filteringstatic Log.LogAutoClosecontext(LNode n)Creates a context from a single LNodestatic Log.LogAutoClosecontext(LNode... nn)Creates a context from multiple LNodesstatic Log.LogAutoClosecontext(LNode parent, java.lang.Object... addData)Creates a context with a parent node and additional datastatic Log.LogAutoClosecontext(java.lang.Object... data)Creates an auto-closeable context that will be automatically popped when closedstatic LNodecreateContext()Creates a context from the current stack onlystatic LNodecreateContext(LNode... data)Creates a new logging context by combining current context with additional nodesstatic LNodecreateContext(java.lang.Object... data)Creates a new logging context by combining current context with additional datastatic LNodedebug(ToString msg, java.lang.Object... data)Logs a DEBUG level message with formatted objectstatic LNodedebug(java.lang.String msg, LNode data)Logs a DEBUG level message with string and single LNodestatic LNodedebug(java.lang.String msg, LNode... data)Logs a DEBUG level message with string and LNode datastatic LNodedebug(java.lang.String msg, java.lang.Object... data)Logs a DEBUG level message with string and key-value pairsstatic LNodeerror(java.lang.String msg, java.lang.Object... data)Logs an ERROR level message without exceptionstatic LNodeerror(java.lang.String msg, java.lang.Throwable throwable, java.lang.Object... data)Logs an ERROR level message with exceptionstatic LNodeerror(java.lang.Throwable throwable, java.lang.Object... data)Logs an ERROR level message from exceptionstatic LNodeget()Gets the current context from the stackstatic java.util.Deque<LNode>getStack()Gets the current context stack for the current threadstatic LNodeinfo(ToString msg, java.lang.Object... data)Logs an INFO level message with formatted objectstatic LNodeinfo(java.lang.String msg, LNode data)Logs an INFO level message with string and single LNodestatic LNodeinfo(java.lang.String msg, LNode... data)Logs an INFO level message with string and LNode datastatic LNodeinfo(java.lang.String msg, java.lang.Object... data)Logs an INFO level message with string and key-value pairsstatic voidlog(LNode node)Logs a custom LNodestatic voidloggerOff()Disables all logging globallystatic voidloggerOn()Enables all logging globallystatic LNodeof(LNode data)Returns the LNode as-is (identity operation)static LNodeof(LNode... data)Creates a composite LNode from multiple LNodesstatic LNodeof(java.lang.Object... data)Creates an LNode from key-value pairsstatic LNodeof2(java.lang.Object[] keys, java.lang.Object[] vals)Creates an LNode from separate key and value arraysstatic LNodeof2(java.util.List<? extends java.lang.CharSequence> keys, java.util.List<?> vals)Creates an LNode from separate key and value listsstatic LNodeofMap(java.util.Map<java.lang.String,?> vals)Creates an LNode from a Mapstatic voidpop(LNode n)Pops a node from the context stackstatic LogPrinterprintConsoleColored()Creates a colored console printer with default filterstatic LogPrinterprintConsoleColored(LogFilter filter)Creates a colored console printer with custom filterstatic LogPrinterprintPlainConsole(LogFilter filter)Creates a plain console printer with custom filterstatic voidpush(LNode n)Pushes a node onto the context stackstatic voidsetStored(java.lang.String nameNode, java.lang.String key, java.lang.Object value)Sets a value in a previously stored named nodestatic voidstoreNode(java.lang.String name, LNode n)Stores a named node for later retrieval and modificationstatic LNodetrace(ToString msg, java.lang.Object... data)Logs a TRACE level message with formatted objectstatic LNodetrace(java.lang.String msg, LNode data)Logs a TRACE level message with string and single LNodestatic LNodetrace(java.lang.String msg, LNode... data)Logs a TRACE level message with string and LNode datastatic LNodetrace(java.lang.String msg, java.lang.Object... data)Logs a TRACE level message with string and key-value pairsstatic LNodewarn(ToString msg, java.lang.Object... data)Logs a WARN level message with formatted objectstatic LNodewarn(java.lang.String msg, LNode data)Logs a WARN level message with string and single LNodestatic LNodewarn(java.lang.String msg, LNode... data)Logs a WARN level message with string and LNode datastatic LNodewarn(java.lang.String msg, java.lang.Object... data)Logs a WARN level message with string and key-value pairsstatic LNodewarn(java.lang.String msg, java.lang.Throwable throwable, java.lang.Object... data)Logs a WARN level message with exceptionstatic <T,T2>
ABiConsumer<T,T2>wrap(ABiConsumer<T,T2> t)Wraps a BiConsumer with current logging contextstatic <T> AConsumer<T>wrap(AConsumer<T> t)Wraps a Consumer with current logging contextstatic <T,R>
AFunction<T,R>wrap(AFunction<T,R> t)Wraps a Function with current logging contextstatic ARunnablewrap(ARunnable t)Wraps a Runnable with current logging contextstatic <T> ASupplier<T>wrap(ASupplier<T> t)Wraps a Supplier with current logging contextstatic java.util.concurrent.ExecutorwrapExecutor(java.util.concurrent.Executor executor)Wraps an Executor to preserve logging context in executed tasksstatic ARunnablewrapRunnable(ARunnable t, java.lang.Object... data)Wraps a Runnable with logging contextstatic <T> ASupplier<T>wrapSupplier(ASupplier<T> t)Wraps a Supplier with current logging context
-
-
-
Field Detail
-
TRACE
public static final boolean TRACE
- See Also:
- Constant Field Values
-
TIME
public static final java.lang.String TIME
- See Also:
- Constant Field Values
-
LEVEL
public static final java.lang.String LEVEL
- See Also:
- Constant Field Values
-
SYSTEM_COMPONENT
public static final java.lang.String SYSTEM_COMPONENT
- See Also:
- Constant Field Values
-
MSG
public static final java.lang.String MSG
- See Also:
- Constant Field Values
-
EXCEPTION_STR
public static final java.lang.String EXCEPTION_STR
- See Also:
- Constant Field Values
-
filter
public static final LogFilter filter
Global logger filter for all log messages
-
DATE_FORMAT
public static final java.text.DateFormat DATE_FORMAT
-
ENABLED
public static boolean ENABLED
Global enabled/disabled state of the logger
-
-
Method Detail
-
storeNode
public static void storeNode(java.lang.String name, LNode n)Stores a named node for later retrieval and modification- Parameters:
name- Unique name for the noden- LNode to store
-
setStored
public static void setStored(java.lang.String nameNode, java.lang.String key, java.lang.Object value)Sets a value in a previously stored named node- Parameters:
nameNode- Name of the stored nodekey- Key to setvalue- Value to set
-
getStack
public static java.util.Deque<LNode> getStack()
Gets the current context stack for the current thread- Returns:
- Deque of LNodes representing the context stack
-
createContext
public static LNode createContext(java.lang.Object... data)
Creates a new logging context by combining current context with additional data- Parameters:
data- Key-value pairs for the context- Returns:
- Combined LNode context
-
createContext
public static LNode createContext(LNode... data)
Creates a new logging context by combining current context with additional nodes- Parameters:
data- LNodes to combine with current context- Returns:
- Combined LNode context
-
createContext
public static LNode createContext()
Creates a context from the current stack only- Returns:
- Current context LNode
-
context
public static Log.LogAutoClose context(java.lang.Object... data)
Creates an auto-closeable context that will be automatically popped when closed- Parameters:
data- Key-value pairs for the context- Returns:
- AutoCloseable context that should be used in try-with-resources
-
context
public static Log.LogAutoClose context(LNode parent, java.lang.Object... addData)
Creates a context with a parent node and additional data- Parameters:
parent- Parent LNodeaddData- Additional key-value pairs- Returns:
- AutoCloseable context
-
context
public static Log.LogAutoClose context(LNode... nn)
Creates a context from multiple LNodes- Parameters:
nn- Array of LNodes to form the context- Returns:
- AutoCloseable context
-
context
public static Log.LogAutoClose context(LNode n)
Creates a context from a single LNode- Parameters:
n- LNode to use as context- Returns:
- AutoCloseable context
-
push
public static void push(LNode n)
Pushes a node onto the context stack- Parameters:
n- LNode to push
-
get
public static LNode get()
Gets the current context from the stack- Returns:
- Current context LNode (combination of all nodes in stack)
-
pop
public static void pop(LNode n)
Pops a node from the context stack- Parameters:
n- Expected node to pop (for validation)
-
log
public static void log(LNode node)
Logs a custom LNode- Parameters:
node- LNode to log
-
trace
public static LNode trace(ToString msg, java.lang.Object... data)
Logs a TRACE level message with formatted object- Parameters:
msg- Message implementing ToString interfacedata- Additional key-value pairs- Returns:
- Created LNode
-
trace
public static LNode trace(java.lang.String msg, LNode... data)
Logs a TRACE level message with string and LNode data- Parameters:
msg- Message stringdata- LNodes with additional data- Returns:
- Created LNode
-
trace
public static LNode trace(java.lang.String msg, LNode data)
Logs a TRACE level message with string and single LNode- Parameters:
msg- Message stringdata- LNode with additional data- Returns:
- Created LNode
-
trace
public static LNode trace(java.lang.String msg, java.lang.Object... data)
Logs a TRACE level message with string and key-value pairs- Parameters:
msg- Message stringdata- Key-value pairs- Returns:
- Created LNode
-
debug
public static LNode debug(ToString msg, java.lang.Object... data)
Logs a DEBUG level message with formatted object- Parameters:
msg- Message implementing ToString interfacedata- Additional key-value pairs- Returns:
- Created LNode
-
debug
public static LNode debug(java.lang.String msg, java.lang.Object... data)
Logs a DEBUG level message with string and key-value pairs- Parameters:
msg- Message stringdata- Key-value pairs- Returns:
- Created LNode
-
debug
public static LNode debug(java.lang.String msg, LNode... data)
Logs a DEBUG level message with string and LNode data- Parameters:
msg- Message stringdata- LNodes with additional data- Returns:
- Created LNode
-
debug
public static LNode debug(java.lang.String msg, LNode data)
Logs a DEBUG level message with string and single LNode- Parameters:
msg- Message stringdata- LNode with additional data- Returns:
- Created LNode
-
info
public static LNode info(ToString msg, java.lang.Object... data)
Logs an INFO level message with formatted object- Parameters:
msg- Message implementing ToString interfacedata- Additional key-value pairs- Returns:
- Created LNode
-
info
public static LNode info(java.lang.String msg, java.lang.Object... data)
Logs an INFO level message with string and key-value pairs- Parameters:
msg- Message stringdata- Key-value pairs- Returns:
- Created LNode
-
info
public static LNode info(java.lang.String msg, LNode... data)
Logs an INFO level message with string and LNode data- Parameters:
msg- Message stringdata- LNodes with additional data- Returns:
- Created LNode
-
info
public static LNode info(java.lang.String msg, LNode data)
Logs an INFO level message with string and single LNode- Parameters:
msg- Message stringdata- LNode with additional data- Returns:
- Created LNode
-
warn
public static LNode warn(ToString msg, java.lang.Object... data)
Logs a WARN level message with formatted object- Parameters:
msg- Message implementing ToString interfacedata- Additional key-value pairs- Returns:
- Created LNode
-
warn
public static LNode warn(java.lang.String msg, java.lang.Object... data)
Logs a WARN level message with string and key-value pairs- Parameters:
msg- Message stringdata- Key-value pairs- Returns:
- Created LNode
-
warn
public static LNode warn(java.lang.String msg, LNode... data)
Logs a WARN level message with string and LNode data- Parameters:
msg- Message stringdata- LNodes with additional data- Returns:
- Created LNode
-
warn
public static LNode warn(java.lang.String msg, LNode data)
Logs a WARN level message with string and single LNode- Parameters:
msg- Message stringdata- LNode with additional data- Returns:
- 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 exception- Parameters:
msg- Message stringthrowable- Exception to logdata- Additional key-value pairs- Returns:
- 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 exception- Parameters:
msg- Message stringthrowable- Exception to logdata- Additional key-value pairs- Returns:
- Created LNode
-
error
public static LNode error(java.lang.String msg, java.lang.Object... data)
Logs an ERROR level message without exception- Parameters:
msg- Message stringdata- Additional key-value pairs- Returns:
- Created LNode
-
error
public static LNode error(java.lang.Throwable throwable, java.lang.Object... data)
Logs an ERROR level message from exception- Parameters:
throwable- Exception to logdata- Additional key-value pairs- Returns:
- Created LNode
-
addFilterNot
public static void addFilterNot(APredicate<LNode> p)
Adds a negative filter (excludes logs that match the predicate)- Parameters:
p- Predicate to exclude matching logs
-
addFilter
public static void addFilter(APredicate<LNode> p)
Adds a positive filter (includes only logs that match the predicate)- Parameters:
p- Predicate to include matching logs
-
printConsoleColored
public static LogPrinter printConsoleColored()
Creates a colored console printer with default filter- Returns:
- LogPrinter instance for colored console output
-
printConsoleColored
public static LogPrinter printConsoleColored(LogFilter filter)
Creates a colored console printer with custom filter- Parameters:
filter- Custom filter for the printer- Returns:
- LogPrinter instance for colored console output
-
printPlainConsole
public static LogPrinter printPlainConsole(LogFilter filter)
Creates a plain console printer with custom filter- Parameters:
filter- Custom filter for the printer- Returns:
- LogPrinter instance for plain console output
-
of
public static LNode of(java.lang.Object... data)
Creates an LNode from key-value pairs- Parameters:
data- Alternating key-value pairs- Returns:
- Created LNode
-
of
public static LNode of(LNode data)
Returns the LNode as-is (identity operation)- Parameters:
data- LNode to return- Returns:
- Same LNode
-
of2
public static LNode of2(java.lang.Object[] keys, java.lang.Object[] vals)
Creates an LNode from separate key and value arrays- Parameters:
keys- Array of keysvals- Array of values- Returns:
- Created LNode
-
of2
public static LNode of2(java.util.List<? extends java.lang.CharSequence> keys, java.util.List<?> vals)
Creates an LNode from separate key and value lists- Parameters:
keys- List of keysvals- List of values- Returns:
- Created LNode
-
ofMap
public static LNode ofMap(java.util.Map<java.lang.String,?> vals)
Creates an LNode from a Map- Parameters:
vals- Map with key-value pairs- Returns:
- Created LNode
-
of
public static LNode of(LNode... data)
Creates a composite LNode from multiple LNodes- Parameters:
data- Array of LNodes to combine- Returns:
- Composite LNode
-
wrapExecutor
public static java.util.concurrent.Executor wrapExecutor(java.util.concurrent.Executor executor)
Wraps an Executor to preserve logging context in executed tasks- Parameters:
executor- Original executor to wrap- Returns:
- Wrapped executor that preserves logging context
-
wrapRunnable
public static ARunnable wrapRunnable(ARunnable t, java.lang.Object... data)
Wraps a Runnable with logging context- Parameters:
t- Runnable to wrapdata- Context data for the wrapper- Returns:
- Wrapped Runnable
-
wrapSupplier
public static <T> ASupplier<T> wrapSupplier(ASupplier<T> t)
Wraps a Supplier with current logging context- Parameters:
t- Supplier to wrap- Returns:
- Wrapped Supplier
-
wrap
public static <T> ASupplier<T> wrap(ASupplier<T> t)
Wraps a Supplier with current logging context- Parameters:
t- Supplier to wrap- Returns:
- Wrapped Supplier
-
wrap
public static ARunnable wrap(ARunnable t)
Wraps a Runnable with current logging context- Parameters:
t- Runnable to wrap- Returns:
- Wrapped Runnable
-
wrap
public static <T> AConsumer<T> wrap(AConsumer<T> t)
Wraps a Consumer with current logging context- Parameters:
t- Consumer to wrap- Returns:
- Wrapped Consumer
-
wrap
public static <T,T2> ABiConsumer<T,T2> wrap(ABiConsumer<T,T2> t)
Wraps a BiConsumer with current logging context- Parameters:
t- BiConsumer to wrap- Returns:
- Wrapped BiConsumer
-
wrap
public static <T,R> AFunction<T,R> wrap(AFunction<T,R> t)
Wraps a Function with current logging context- Parameters:
t- Function to wrap- Returns:
- Wrapped Function
-
loggerOff
public static void loggerOff()
Disables all logging globally
-
loggerOn
public static void loggerOn()
Enables all logging globally
-
-