Interface Logger

All Superinterfaces:
Filtered<LogEntry>, Flushable, Listener, NamedObject, Receiver<Transmittable>, Transceiver
All Known Implementing Classes:
BaseLogger, ConsoleLogger, LogServiceLogger, NullLogger

public interface Logger extends Listener, Filtered<LogEntry>, Flushable
A Logger accepts Messages via log(Message) and writes them to one or more Logs. Filters can be added to the logger to restrict which messages are logged with addFilter(Filter).

Markdown Documentation

For a detailed discussion, see the KivaKit Logging Documentation


Loggers listen for messages via Listener.onReceive(Transmittable) and forward them to log(Message). This means that Loggers can be used anywhere a Listener is required. For example when using a converter, the converter can broadcast warning or problem messages during a conversion and a Logger can listen to and log those messages.


 private static final Logger LOGGER = LoggerFactory.newLogger();


 var converter = new IntegerConverter(LOGGER);
 var agent = converter.convert("99");
Another typical use case is for a logger to listen to an object that implements Repeater.


 class ReportProcessor extends BaseRepeater<Message> { [...] }


 var reporter = LOGGER.listenTo(new ReportProcessor());
Logs are loaded dynamically through using the service provider interface (SPI) Log. Which log implementation(s) are loaded for use in an application can be chosen by the end-user from the command line with the system property KIVAKIT_LOG.
jonathanl (shibo)
See Also:
KivaKit Logging Documentation, LogEntry, Listener, Filtered, Filter, Flushable
  • Method Details

    • addFilter

      void addFilter(Filter<LogEntry> filter)
      Set a new filter
      filter - The filter to set
    • codeContext

      LoggerCodeContext codeContext()
      Not public API
      The code context from which this logger is logging
    • log

      void log(Message message)
      Logs the given message
      message - The message to log
    • log

      void log(LoggerCodeContext context, Thread thread, Message message)
      Not public API

      This method is only for integrating other logging frameworks which have their own idea of logging context, like log4j or Java logging.

      context - The logging context
      message - The message
    • onMessage

      default void onMessage(Message message)
      Logs any received messages
      Specified by:
      onMessage in interface Listener
    • startTime

      Time startTime()
      The time this logger was constructed