Class LoggerRegistry<T extends ExtendedLogger>

java.lang.Object
org.apache.logging.log4j.spi.LoggerRegistry<T>

public class LoggerRegistry<T extends ExtendedLogger> extends Object
Convenience class to be used as an ExtendedLogger registry by LoggerContext implementations.
  • Constructor Details

    • LoggerRegistry

      public LoggerRegistry()
    • LoggerRegistry

      public LoggerRegistry(LoggerRegistry.MapFactory<T> mapFactory)
      Constructs an instance ignoring the given the map factory.
      Parameters:
      mapFactory - a map factory
  • Method Details

    • getLogger

      public @Nullable T getLogger(String name)
      Returns the logger associated with the given name.

      There can be made no assumptions on the message factory of the returned logger. Callers are strongly advised to switch to getLogger(String, MessageFactory) and provide a message factory parameter!

      Parameters:
      name - a logger name
      Returns:
      the logger associated with the name
    • getLogger

      public @Nullable T getLogger(String name, @Nullable MessageFactory messageFactory)
      Returns the logger associated with the given name and message factory.

      In the absence of a message factory, there can be made no assumptions on the message factory of the returned logger. This lenient behaviour is only kept for backward compatibility. Callers are strongly advised to provide a message factory parameter to the method!

      Parameters:
      name - a logger name
      messageFactory - a message factory
      Returns:
      the logger associated with the given name and message factory
    • getLoggers

      public Collection<T> getLoggers()
    • getLoggers

      public Collection<T> getLoggers(Collection<T> destination)
    • hasLogger

      public boolean hasLogger(String name)
      Checks if a logger associated with the given name exists.

      There can be made no assumptions on the message factory of the found logger. Callers are strongly advised to switch to hasLogger(String, MessageFactory) and provide a message factory parameter!

      Parameters:
      name - a logger name
      Returns:
      true, if the logger exists; false otherwise.
    • hasLogger

      public boolean hasLogger(String name, MessageFactory messageFactory)
      Checks if a logger associated with the given name and message factory exists.

      In the absence of a message factory, there can be made no assumptions on the message factory of the found logger. This lenient behaviour is only kept for backward compatibility. Callers are strongly advised to provide a message factory parameter to the method!

      Parameters:
      name - a logger name
      messageFactory - a message factory
      Returns:
      true, if the logger exists; false otherwise.
      Since:
      2.5
    • hasLogger

      public boolean hasLogger(String name, Class<? extends MessageFactory> messageFactoryClass)
      Checks if a logger associated with the given name and message factory type exists.
      Parameters:
      name - a logger name
      messageFactoryClass - a message factory class
      Returns:
      true, if the logger exists; false otherwise.
      Since:
      2.5
    • putIfAbsent

      public void putIfAbsent(String name, @Nullable MessageFactory messageFactory, T logger)
      Registers the provided logger.

      The logger will be registered using the keys provided by the name and messageFactory parameters and the values of Logger.getName() and Logger.getMessageFactory().

      Parameters:
      name - a logger name
      messageFactory - a message factory
      logger - a logger instance