Top Description Fields Constructors Methods
org.apache.logging.log4j.spi

public abstract Class AbstractLoggerAdapter<L>

extends Object
implements LoggerAdapter<L>, LoggerContextShutdownAware
Class Inheritance
All Implemented Interfaces
org.apache.logging.log4j.spi.LoggerContextShutdownAware, org.apache.logging.log4j.spi.LoggerAdapter, java.io.Closeable, java.lang.AutoCloseable
Type Parameters
<L>
the Logger class to adapt
Imports
java.util.HashSet, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock, org.apache.logging.log4j.LogManager, org.apache.logging.log4j.util.LoaderUtil

Provides an abstract base class to use for implementing LoggerAdapter.
Since
2.1

Field Summary

Modifier and TypeField and Description
private final ReadWriteLock
protected final Map<LoggerContext, ConcurrentMap<String, L>>
registry

A map to store loggers for their given LoggerContexts.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public void
protected abstract LoggerContext

Returns:

the LoggerContext to be used for lookup and creation purposes
getContext
()

Gets the LoggerContext that should be used to look up or create loggers.

protected LoggerContext

Returns:

the LoggerContext for the calling class
getContext
(final Class<?>
the caller class
callerClass
)

Gets the LoggerContext associated with the given caller class.

public L
getLogger(final String
the name of the logger to get
name
)

Implements org.apache.logging.log4j.spi.LoggerAdapter.getLogger.

Gets a named logger.

public Set<LoggerContext>
getLoggerContexts()

For unit testing.

public ConcurrentMap<String, L>

Returns:

the map of loggers for the given LoggerContext
getLoggersInContext
(final LoggerContext
the LoggerContext to get loggers for
context
)

Gets or creates the ConcurrentMap of named loggers for a given LoggerContext.

protected abstract L

Returns:

the new named logger
newLogger
(final String
the name of the logger to create
name
,
final LoggerContext
the LoggerContext this logger will be associated with
context
)

Creates a new named logger for a given LoggerContext.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lockback to summary
private final ReadWriteLock lock
registryback to summary
protected final Map<LoggerContext, ConcurrentMap<String, L>> registry

A map to store loggers for their given LoggerContexts.

Constructor Detail

AbstractLoggerAdapterback to summary
public AbstractLoggerAdapter()

Method Detail

closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
contextShutdownback to summary
public void contextShutdown(final LoggerContext loggerContext)

Implements org.apache.logging.log4j.spi.LoggerContextShutdownAware.contextShutdown.

Annotations
@Override
getContextback to summary
protected abstract LoggerContext getContext()

Gets the LoggerContext that should be used to look up or create loggers. This is similar in spirit to the ContextSelector class in log4j-core. However, implementations can rely on their own framework's separation of contexts instead (or simply use a singleton).

Returns:LoggerContext

the LoggerContext to be used for lookup and creation purposes

See Also
org.apache.logging.log4j.LogManager#getContext(ClassLoader, boolean), org.apache.logging.log4j.LogManager#getContext(String, boolean)
getContextback to summary
protected LoggerContext getContext(final Class<?> callerClass)

Gets the LoggerContext associated with the given caller class.

Parameters
callerClass:Class<?>

the caller class

Returns:LoggerContext

the LoggerContext for the calling class

getLoggerback to summary
public L getLogger(final String name)

Implements org.apache.logging.log4j.spi.LoggerAdapter.getLogger.

Doc from org.apache.logging.log4j.spi.LoggerAdapter.getLogger.

Gets a named logger. Implementations should defer to the abstract methods in AbstractLoggerAdapter.

Parameters
name:String

the name of the logger to get

Returns:L

the named logger

Annotations
@Override
getLoggerContextsback to summary
public Set<LoggerContext> getLoggerContexts()

For unit testing. Consider to be private.

getLoggersInContextback to summary
public ConcurrentMap<String, L> getLoggersInContext(final LoggerContext context)

Gets or creates the ConcurrentMap of named loggers for a given LoggerContext.

Parameters
context:LoggerContext

the LoggerContext to get loggers for

Returns:ConcurrentMap<String, L>

the map of loggers for the given LoggerContext

newLoggerback to summary
protected abstract L newLogger(final String name, final LoggerContext context)

Creates a new named logger for a given LoggerContext.

Parameters
name:String

the name of the logger to create

context:LoggerContext

the LoggerContext this logger will be associated with

Returns:L

the new named logger