org.apache.logging.log4j.spi
Class AbstractLoggerAdapter<L>

java.lang.Object
  extended by org.apache.logging.log4j.spi.AbstractLoggerAdapter<L>
Type Parameters:
L - the Logger class to adapt
All Implemented Interfaces:
Closeable, LoggerAdapter<L>

public abstract class AbstractLoggerAdapter<L>
extends Object
implements LoggerAdapter<L>

Provides an abstract base class to use for implementing LoggerAdapter.

Since:
2.1

Field Summary
protected  Map<LoggerContext,ConcurrentMap<String,L>> registry
          A map to store loggers for their given LoggerContexts.
 
Constructor Summary
AbstractLoggerAdapter()
           
 
Method Summary
 void close()
           
protected abstract  LoggerContext getContext()
          Gets the LoggerContext that should be used to look up or create loggers.
protected  LoggerContext getContext(Class<?> callerClass)
          Gets the LoggerContext associated with the given caller class.
 L getLogger(String name)
          Gets a named logger.
 ConcurrentMap<String,L> getLoggersInContext(LoggerContext context)
          Gets or creates the ConcurrentMap of named loggers for a given LoggerContext.
protected abstract  L newLogger(String name, LoggerContext context)
          Creates a new named logger for a given LoggerContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registry

protected final Map<LoggerContext,ConcurrentMap<String,L>> registry
A map to store loggers for their given LoggerContexts.

Constructor Detail

AbstractLoggerAdapter

public AbstractLoggerAdapter()
Method Detail

getLogger

public L getLogger(String name)
Description copied from interface: LoggerAdapter
Gets a named logger. Implementations should defer to the abstract methods in AbstractLoggerAdapter.

Specified by:
getLogger in interface LoggerAdapter<L>
Parameters:
name - the name of the logger to get
Returns:
the named logger

getLoggersInContext

public ConcurrentMap<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

newLogger

protected abstract L newLogger(String name,
                               LoggerContext context)
Creates a new named logger for a given LoggerContext.

Parameters:
name - the name of the logger to create
context - the LoggerContext this logger will be associated with
Returns:
the new named logger

getContext

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:
the LoggerContext to be used for lookup and creation purposes
See Also:
LogManager.getContext(ClassLoader, boolean), LogManager.getContext(String, boolean)

getContext

protected LoggerContext getContext(Class<?> callerClass)
Gets the LoggerContext associated with the given caller class.

Parameters:
callerClass - the caller class
Returns:
the LoggerContext for the calling class

close

public void close()
Specified by:
close in interface Closeable


Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.