Class ThreadedLogRecordDispatcher

java.lang.Object
java.lang.Thread
eu.cloudnetservice.common.log.defaults.ThreadedLogRecordDispatcher
All Implemented Interfaces:
LogRecordDispatcher, Runnable

public final class ThreadedLogRecordDispatcher extends Thread implements LogRecordDispatcher
A log record dispatcher which dispatches requested log records on a single thread one at a time.
Since:
4.0
  • Field Details

  • 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

      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

      public void dispatchRecord(@NonNull @NonNull Logger logger, @NonNull @NonNull LogRecord record)
      Called when a log record needs to be dispatched for a logger.
      Specified by:
      dispatchRecord in interface LogRecordDispatcher
      Parameters:
      logger - the logger from which the log event came.
      record - the record which needs to be dispatched.
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread