Class ThreadedLogRecordDispatcher
java.lang.Object
java.lang.Thread
eu.cloudnetservice.common.log.defaults.ThreadedLogRecordDispatcher
- All Implemented Interfaces:
LogRecordDispatcher,Runnable
A log record dispatcher which dispatches requested log records on a single thread one at a time.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Loggerprivate final BlockingQueue<LogRecord>static final StringFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateThreadedLogRecordDispatcher(@NonNull Logger logger, @NonNull String threadName) Constructs a new threaded log record dispatcher instance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatchRecord(@NonNull Logger logger, @NonNull LogRecord record) Called when a log record needs to be dispatched for a logger.Creates a new threaded log record dispatcher instance using the given logger as the target and formatting the default thread name format using the given loggers name.newInstance(@NonNull Logger logger, @NonNull String threadName) Creates a new threaded log record dispatcher instance using the given logger as the target and the given thread name.voidrun()Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
THREAD_NAME_FORMAT
- See Also:
-
logger
-
queue
-
-
Constructor Details
-
ThreadedLogRecordDispatcher
private ThreadedLogRecordDispatcher(@NonNull @NonNull Logger logger, @NonNull @NonNull String threadName) Constructs a new threaded log record dispatcher instance. This automatically starts the thread.- Parameters:
logger- the logger to which log records should get logged.threadName- the name of the thread to use.- Throws:
NullPointerException- if the given logger or thread name is null.
-
-
Method Details
-
forLogger
@NonNull public static @NonNull ThreadedLogRecordDispatcher forLogger(@NonNull @NonNull Logger logger) Creates a new threaded log record dispatcher instance using the given logger as the target and formatting the default thread name format using the given loggers name.- Parameters:
logger- the logger this dispatcher should pump requests to.- Returns:
- a new threaded log record dispatcher instance.
- Throws:
NullPointerException- if the given logger is null.
-
newInstance
@NonNull public static @NonNull ThreadedLogRecordDispatcher newInstance(@NonNull @NonNull Logger logger, @NonNull @NonNull String threadName) Creates a new threaded log record dispatcher instance using the given logger as the target and the given thread name.- Parameters:
logger- the logger this dispatcher should pump requests to.threadName- the name of the dispatcher thread to use.- Returns:
- a new threaded log record dispatcher instance.
- Throws:
NullPointerException- if the given logger or thread name is null.
-
dispatchRecord
Called when a log record needs to be dispatched for a logger.- Specified by:
dispatchRecordin interfaceLogRecordDispatcher- Parameters:
logger- the logger from which the log event came.record- the record which needs to be dispatched.
-
run
public void run()
-