org.apache.logging.log4j.core
Class LoggerContext

java.lang.Object
  extended by org.apache.logging.log4j.core.LoggerContext
All Implemented Interfaces:
ConfigurationListener, LifeCycle, org.apache.logging.log4j.spi.LoggerContext

public class LoggerContext
extends Object
implements org.apache.logging.log4j.spi.LoggerContext, ConfigurationListener, LifeCycle

The LoggerContext is the anchor for the logging system. It maintains a list of all the loggers requested by applications and a reference to the Configuration. The Configuration will contain the configured loggers, appenders, filters, etc and will be atomically updated whenever a reconfigure occurs.


Nested Class Summary
static class LoggerContext.Status
          Status of the LoggerContext.
 
Constructor Summary
LoggerContext(String name)
          Constructor taking only a name.
LoggerContext(String name, Object externalContext)
          Constructor taking a name and a reference to an external context.
LoggerContext(String name, Object externalContext, String configLocn)
          Constructor taking a name external context and a configuration location String.
LoggerContext(String name, Object externalContext, URI configLocn)
          Constructor taking a name, external context and a configuration URI.
 
Method Summary
 void addFilter(Filter filter)
          Add a Filter to the Configuration.
 Configuration getConfiguration()
          Returns the current Configuration.
 Object getExternalContext()
          Returns the external context.
 Logger getLogger(String name)
          Obtain a Logger from the Context.
 String getName()
          Gets the name.
 LoggerContext.Status getStatus()
           
 boolean hasLogger(String name)
          Determine if the specified Logger exists.
 boolean isStarted()
           
 void onChange(Reconfigurable reconfigurable)
          Cause a reconfiguration to take place when the underlying configuration file changes.
 void reconfigure()
          Reconfigure the context.
 void removeFiler(Filter filter)
          Removes a Filter from the current Configuration.
 Configuration setConfiguration(Configuration config)
          Set the Configuration to be used.
 void setExternalContext(Object context)
          Set the external context.
 void start()
           
 void stop()
           
 void updateLoggers()
          Cause all Loggers to be updated against the current Configuration.
 void updateLoggers(Configuration config)
          Cause all Logger to be updated against the specified Configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggerContext

public LoggerContext(String name)
Constructor taking only a name.

Parameters:
name - The context name.

LoggerContext

public LoggerContext(String name,
                     Object externalContext)
Constructor taking a name and a reference to an external context.

Parameters:
name - The context name.
externalContext - The external context.

LoggerContext

public LoggerContext(String name,
                     Object externalContext,
                     URI configLocn)
Constructor taking a name, external context and a configuration URI.

Parameters:
name - The context name.
externalContext - The external context.
configLocn - The location of the configuration as a URI.

LoggerContext

public LoggerContext(String name,
                     Object externalContext,
                     String configLocn)
Constructor taking a name external context and a configuration location String. The location must be resolvable to a File.

Parameters:
name - The configuration location.
externalContext - The external context.
configLocn - The configuration location.
Method Detail

start

public void start()
Specified by:
start in interface LifeCycle

stop

public void stop()
Specified by:
stop in interface LifeCycle

getName

public String getName()
Gets the name.

Returns:
the name.

getStatus

public LoggerContext.Status getStatus()

isStarted

public boolean isStarted()
Specified by:
isStarted in interface LifeCycle

setExternalContext

public void setExternalContext(Object context)
Set the external context.

Parameters:
context - The external context.

getExternalContext

public Object getExternalContext()
Returns the external context.

Specified by:
getExternalContext in interface org.apache.logging.log4j.spi.LoggerContext
Returns:
The external context.

getLogger

public Logger getLogger(String name)
Obtain a Logger from the Context.

Specified by:
getLogger in interface org.apache.logging.log4j.spi.LoggerContext
Parameters:
name - The name of the Logger to return.
Returns:
The Logger.

hasLogger

public boolean hasLogger(String name)
Determine if the specified Logger exists.

Specified by:
hasLogger in interface org.apache.logging.log4j.spi.LoggerContext
Parameters:
name - The Logger name to search for.
Returns:
True if the Logger exists, false otherwise.

getConfiguration

public Configuration getConfiguration()
Returns the current Configuration. The Configuration will be replaced when a reconfigure occurs.

Returns:
The Configuration.

addFilter

public void addFilter(Filter filter)
Add a Filter to the Configuration. Filters that are added through the API will be lost when a reconfigure occurs.

Parameters:
filter - The Filter to add.

removeFiler

public void removeFiler(Filter filter)
Removes a Filter from the current Configuration.

Parameters:
filter - The Filter to remove.

setConfiguration

public Configuration setConfiguration(Configuration config)
Set the Configuration to be used.

Parameters:
config - The new Configuration.
Returns:
The previous Configuration.

reconfigure

public void reconfigure()
Reconfigure the context.


updateLoggers

public void updateLoggers()
Cause all Loggers to be updated against the current Configuration.


updateLoggers

public void updateLoggers(Configuration config)
Cause all Logger to be updated against the specified Configuration.

Parameters:
config - The Configuration.

onChange

public void onChange(Reconfigurable reconfigurable)
Cause a reconfiguration to take place when the underlying configuration file changes.

Specified by:
onChange in interface ConfigurationListener
Parameters:
reconfigurable - The Configuration that can be reconfigured.


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