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

Messaging

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.

Example

 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.

Example

 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.
Author:
jonathanl (shibo)
See Also:
KivaKit Logging Documentation, LogEntry, Listener, Filtered, Filter, Flushable
  • Method Details

    • addFilter

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

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

      void log(Message message)
      Logs the given message
      Parameters:
      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.

      Parameters:
      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()
      Returns:
      The time this logger was constructed