Package org.apache.logging.log4j.spi
Class AbstractLoggerAdapter<L>
- java.lang.Object
-
- org.apache.logging.log4j.spi.AbstractLoggerAdapter<L>
-
- Type Parameters:
L- the Logger class to adapt
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,LoggerAdapter<L>,LoggerContextShutdownAware
- Direct Known Subclasses:
AbstractLoggerAdapter,Hierarchy.PrivateLoggerAdapter,Log4jLoggerFactory,Log4jSystemLoggerAdapter,LogAdapter
public abstract class AbstractLoggerAdapter<L> extends java.lang.Object implements LoggerAdapter<L>, LoggerContextShutdownAware
Provides an abstract base class to use for implementing LoggerAdapter.- Since:
- 2.1
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.locks.ReadWriteLocklockprotected java.util.Map<LoggerContext,java.util.concurrent.ConcurrentMap<java.lang.String,L>>registryA map to store loggers for their given LoggerContexts.
-
Constructor Summary
Constructors Constructor Description AbstractLoggerAdapter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()voidcontextShutdown(LoggerContext loggerContext)protected abstract LoggerContextgetContext()Gets theLoggerContextthat should be used to look up or create loggers.protected LoggerContextgetContext(java.lang.Class<?> callerClass)Gets theLoggerContextassociated with the given caller class.LgetLogger(java.lang.String name)Gets a named logger.java.util.Set<LoggerContext>getLoggerContexts()For unit testing.java.util.concurrent.ConcurrentMap<java.lang.String,L>getLoggersInContext(LoggerContext context)Gets or creates the ConcurrentMap of named loggers for a given LoggerContext.protected abstract LnewLogger(java.lang.String name, LoggerContext context)Creates a new named logger for a givenLoggerContext.
-
-
-
Field Detail
-
registry
protected final java.util.Map<LoggerContext,java.util.concurrent.ConcurrentMap<java.lang.String,L>> registry
A map to store loggers for their given LoggerContexts.
-
lock
private final java.util.concurrent.locks.ReadWriteLock lock
-
-
Method Detail
-
getLogger
public L getLogger(java.lang.String name)
Description copied from interface:LoggerAdapterGets a named logger. Implementations should defer to the abstract methods inAbstractLoggerAdapter.- Specified by:
getLoggerin interfaceLoggerAdapter<L>- Parameters:
name- the name of the logger to get- Returns:
- the named logger
-
contextShutdown
public void contextShutdown(LoggerContext loggerContext)
- Specified by:
contextShutdownin interfaceLoggerContextShutdownAware
-
getLoggersInContext
public java.util.concurrent.ConcurrentMap<java.lang.String,L> getLoggersInContext(LoggerContext context)
Gets or creates the ConcurrentMap of named loggers for a given LoggerContext.- Parameters:
context- the LoggerContext to get loggers for- Returns:
- the map of loggers for the given LoggerContext
-
getLoggerContexts
public java.util.Set<LoggerContext> getLoggerContexts()
For unit testing. Consider to be private.
-
newLogger
protected abstract L newLogger(java.lang.String name, LoggerContext context)
Creates a new named logger for a givenLoggerContext.- Parameters:
name- the name of the logger to createcontext- the LoggerContext this logger will be associated with- Returns:
- the new named logger
-
getContext
protected abstract LoggerContext getContext()
Gets theLoggerContextthat should be used to look up or create loggers. This is similar in spirit to theContextSelectorclass inlog4j-core. However, implementations can rely on their own framework's separation of contexts instead (or simply use a singleton).- Returns:
- the LoggerContext to be used for lookup and creation purposes
- See Also:
LogManager.getContext(ClassLoader, boolean),LogManager.getContext(String, boolean)
-
getContext
protected LoggerContext getContext(java.lang.Class<?> callerClass)
Gets theLoggerContextassociated with the given caller class.- Parameters:
callerClass- the caller class- Returns:
- the LoggerContext for the calling class
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-