Class LoggerRegistry<T extends ExtendedLogger>
- java.lang.Object
-
- org.apache.logging.log4j.spi.LoggerRegistry<T>
-
@NullMarked public class LoggerRegistry<T extends ExtendedLogger> extends java.lang.ObjectConvenience class to be used as anExtendedLoggerregistry byLoggerContextimplementations.- Since:
- 2.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLoggerRegistry.ConcurrentMapFactory<T extends ExtendedLogger>Deprecated.As of version2.25.0, planned to be removed!static interfaceLoggerRegistry.MapFactory<T extends ExtendedLogger>Deprecated.As of version2.25.0, planned to be removed!static classLoggerRegistry.WeakMapFactory<T extends ExtendedLogger>Deprecated.As of version2.25.0, planned to be removed!
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.locks.ReadWriteLocklockprivate java.util.Map<java.lang.String,java.util.Map<MessageFactory,T>>loggerByMessageFactoryByNameprivate java.util.concurrent.locks.LockreadLockprivate java.util.concurrent.locks.LockwriteLock
-
Constructor Summary
Constructors Constructor Description LoggerRegistry()LoggerRegistry(@Nullable LoggerRegistry.MapFactory<T> mapFactory)Deprecated.As of version2.25.0, planned to be removed!
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private java.util.Map<MessageFactory,T>createLoggerRefByMessageFactoryMap(java.lang.String ignored)@Nullable TgetLogger(java.lang.String name)Deprecated.As of version2.25.0, planned to be removed! UsegetLogger(String, MessageFactory)instead.@Nullable TgetLogger(java.lang.String name, @Nullable MessageFactory messageFactory)Returns the logger associated with the given name and message factory.java.util.Collection<T>getLoggers()java.util.Collection<T>getLoggers(java.util.Collection<T> destination)booleanhasLogger(java.lang.String name)Deprecated.As of version2.25.0, planned to be removed! UsehasLogger(String, MessageFactory)instead.booleanhasLogger(java.lang.String name, @Nullable MessageFactory messageFactory)Checks if a logger associated with the given name and message factory exists.booleanhasLogger(java.lang.String name, java.lang.Class<? extends MessageFactory> messageFactoryClass)Checks if a logger associated with the given name and message factory type exists.voidputIfAbsent(java.lang.String name, @Nullable MessageFactory messageFactory, T logger)Registers the provided logger.
-
-
-
Field Detail
-
loggerByMessageFactoryByName
private final java.util.Map<java.lang.String,java.util.Map<MessageFactory,T extends ExtendedLogger>> loggerByMessageFactoryByName
-
lock
private final java.util.concurrent.locks.ReadWriteLock lock
-
readLock
private final java.util.concurrent.locks.Lock readLock
-
writeLock
private final java.util.concurrent.locks.Lock writeLock
-
-
Constructor Detail
-
LoggerRegistry
public LoggerRegistry()
-
LoggerRegistry
@Deprecated public LoggerRegistry(@Nullable LoggerRegistry.MapFactory<T> mapFactory)
Deprecated.As of version2.25.0, planned to be removed!Constructs an instance ignoring the given the map factory.- Parameters:
mapFactory- a map factory
-
-
Method Detail
-
getLogger
@Deprecated public @Nullable T getLogger(java.lang.String name)
Deprecated.As of version2.25.0, planned to be removed! UsegetLogger(String, MessageFactory)instead.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(java.lang.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 namemessageFactory- a message factory- Returns:
- the logger associated with the given name and message factory
-
getLoggers
public java.util.Collection<T> getLoggers()
-
hasLogger
@Deprecated public boolean hasLogger(java.lang.String name)
Deprecated.As of version2.25.0, planned to be removed! UsehasLogger(String, MessageFactory)instead.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;falseotherwise.
-
hasLogger
public boolean hasLogger(java.lang.String name, @Nullable 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 namemessageFactory- a message factory- Returns:
true, if the logger exists;falseotherwise.- Since:
- 2.5
-
hasLogger
public boolean hasLogger(java.lang.String name, java.lang.Class<? extends MessageFactory> messageFactoryClass)Checks if a logger associated with the given name and message factory type exists.- Parameters:
name- a logger namemessageFactoryClass- a message factory class- Returns:
true, if the logger exists;falseotherwise.- Since:
- 2.5
-
putIfAbsent
public void putIfAbsent(java.lang.String name, @Nullable MessageFactory messageFactory, T logger)Registers the provided logger.The logger will be registered using the keys provided by the
nameandmessageFactoryparameters and the values ofLogger.getName()andLogger.getMessageFactory().- Parameters:
name- a logger namemessageFactory- a message factorylogger- a logger instance
-
createLoggerRefByMessageFactoryMap
private java.util.Map<MessageFactory,T> createLoggerRefByMessageFactoryMap(java.lang.String ignored)
-
-