Package org.apache.logging.log4j.spi
Class LoggerRegistry<T extends ExtendedLogger>
- java.lang.Object
-
- org.apache.logging.log4j.spi.LoggerRegistry<T>
-
public class LoggerRegistry<T extends ExtendedLogger> extends java.lang.Object
Convenience class to be used byLoggerContext
implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LoggerRegistry.ConcurrentMapFactory<T extends ExtendedLogger>
Generates ConcurrentHashMaps for use by the registry to store the Loggers.static interface
LoggerRegistry.MapFactory<T extends ExtendedLogger>
Interface to control the data structure used by the registry to store the Loggers.static class
LoggerRegistry.WeakMapFactory<T extends ExtendedLogger>
Generates WeakHashMaps for use by the registry to store the Loggers.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
DEFAULT_FACTORY_KEY
private LoggerRegistry.MapFactory<T>
factory
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,T>>
map
-
Constructor Summary
Constructors Constructor Description LoggerRegistry()
LoggerRegistry(LoggerRegistry.MapFactory<T> factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
factoryClassKey(java.lang.Class<? extends MessageFactory> messageFactoryClass)
private static java.lang.String
factoryKey(MessageFactory messageFactory)
T
getLogger(java.lang.String name)
Returns an ExtendedLogger.T
getLogger(java.lang.String name, MessageFactory messageFactory)
Returns an ExtendedLogger.java.util.Collection<T>
getLoggers()
java.util.Collection<T>
getLoggers(java.util.Collection<T> destination)
private java.util.Map<java.lang.String,T>
getOrCreateInnerMap(java.lang.String factoryName)
boolean
hasLogger(java.lang.String name)
Detects if a Logger with the specified name exists.boolean
hasLogger(java.lang.String name, java.lang.Class<? extends MessageFactory> messageFactoryClass)
Detects if a Logger with the specified name and MessageFactory type exists.boolean
hasLogger(java.lang.String name, MessageFactory messageFactory)
Detects if a Logger with the specified name and MessageFactory exists.void
putIfAbsent(java.lang.String name, MessageFactory messageFactory, T logger)
-
-
-
Field Detail
-
DEFAULT_FACTORY_KEY
private static final java.lang.String DEFAULT_FACTORY_KEY
-
factory
private final LoggerRegistry.MapFactory<T extends ExtendedLogger> factory
-
map
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,T extends ExtendedLogger>> map
-
-
Constructor Detail
-
LoggerRegistry
public LoggerRegistry()
-
LoggerRegistry
public LoggerRegistry(LoggerRegistry.MapFactory<T> factory)
-
-
Method Detail
-
factoryClassKey
private static java.lang.String factoryClassKey(java.lang.Class<? extends MessageFactory> messageFactoryClass)
-
factoryKey
private static java.lang.String factoryKey(MessageFactory messageFactory)
-
getLogger
public T getLogger(java.lang.String name)
Returns an ExtendedLogger.- Parameters:
name
- The name of the Logger to return.- Returns:
- The logger with the specified name.
-
getLogger
public T getLogger(java.lang.String name, MessageFactory messageFactory)
Returns an ExtendedLogger.- Parameters:
name
- The name of the Logger to return.messageFactory
- The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched.- Returns:
- The logger with the specified name.
-
getLoggers
public java.util.Collection<T> getLoggers()
-
getOrCreateInnerMap
private java.util.Map<java.lang.String,T> getOrCreateInnerMap(java.lang.String factoryName)
-
hasLogger
public boolean hasLogger(java.lang.String name)
Detects if a Logger with the specified name exists.- Parameters:
name
- The Logger name to search for.- Returns:
- true if the Logger exists, false otherwise.
-
hasLogger
public boolean hasLogger(java.lang.String name, MessageFactory messageFactory)
Detects if a Logger with the specified name and MessageFactory exists.- Parameters:
name
- The Logger name to search for.messageFactory
- The message factory to search for.- Returns:
- true if the Logger exists, false otherwise.
- Since:
- 2.5
-
hasLogger
public boolean hasLogger(java.lang.String name, java.lang.Class<? extends MessageFactory> messageFactoryClass)
Detects if a Logger with the specified name and MessageFactory type exists.- Parameters:
name
- The Logger name to search for.messageFactoryClass
- The message factory class to search for.- Returns:
- true if the Logger exists, false otherwise.
- Since:
- 2.5
-
putIfAbsent
public void putIfAbsent(java.lang.String name, MessageFactory messageFactory, T logger)
-
-