Logger. The method getLogger() is provided as the most convenient way to obtain a named Logger based
on the calling class name. This class also provides method for obtaining named Loggers that use
String#format(String, Object...) style messages instead of the default type of parameterized messages. These
are obtained through the getFormatterLogger(Class) family of methods. Other service provider methods are
given through the getContext() and getFactory() family of methods; these methods are not normally
useful for typical usage of Log4j.
| Modifier and Type | Field and Description |
|---|---|
| private static volatile LoggerContextFactory | |
| public static final String | FACTORY_PROPERTY_NAME
Log4j property to set to the fully qualified class name of a custom implementation of
|
| private static final String | |
| private static final Logger | |
| public static final String | ROOT_LOGGER_NAME
The name of the root Logger is . |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| private static Class | |
| public static boolean | |
| public static LoggerContext | |
| public static LoggerContext | Returns: a LoggerContext.if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext)Returns a LoggerContext. |
| public static LoggerContext | Returns: a LoggerContext.The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext)Returns a LoggerContext. |
| public static LoggerContext | Returns: a LoggerContext.The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext, final Object An external context (such as a ServletContext) to be associated with the LoggerContext. externalContext)Returns a LoggerContext. |
| public static LoggerContext | Returns: a LoggerContext.The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext, final URI The URI for the configuration to use. configLocation)Returns a LoggerContext. |
| public static LoggerContext | Returns: a LoggerContext.The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext, final Object An external context (such as a ServletContext) to be associated with the LoggerContext. externalContext, final URI The URI for the configuration to use. configLocation)Returns a LoggerContext. |
| public static LoggerContext | Returns: a LoggerContext.The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext, final Object An external context (such as a ServletContext) to be associated with the LoggerContext. externalContext, final URI The URI for the configuration to use. configLocation, final String The LoggerContext name. name)Returns a LoggerContext. |
| protected static LoggerContext | Returns: a LoggerContext.The fully qualified class name of the Class that this method is a member of. fqcn, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext)Returns a LoggerContext |
| protected static LoggerContext | Returns: a LoggerContext.The fully qualified class name of the Class that this method is a member of. fqcn, final ClassLoader The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext)Returns a LoggerContext |
| protected static LoggerContext | Returns: a LoggerContext.The fully qualified class name of the Class that this method is a member of. fqcn, final ClassLoader The ClassLoader for the context. If null the context will attempt to determine the appropriate
ClassLoader. loader, final boolean if false the LoggerContext appropriate for the caller of this method is returned. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
returned and if the caller is a class in the container's classpath then a different LoggerContext may
be returned. If true then only a single LoggerContext will be returned. currentContext, final URI The URI for the configuration to use. configLocation, final String The LoggerContext name. name)Returns a LoggerContext |
| public static LoggerContextFactory | |
| public static Logger | Returns: The Logger for the calling class.Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name. |
| public static Logger | Returns: The Logger, created with aStringFormatterMessageFactoryThe Class whose name should be used as the Logger name. clazz)Returns a formatter Logger using the fully qualified name of the Class as the Logger name. |
| public static Logger | Returns: The Logger, created with aStringFormatterMessageFactoryThe value's whose class name should be used as the Logger name. value)Returns a formatter Logger using the fully qualified name of the value's Class as the Logger name. |
| public static Logger | Returns: The Logger, created with aStringFormatterMessageFactoryThe logger name. If null it will default to the name of the calling class. name)Returns a formatter Logger with the specified name. |
| public static Logger | Returns: The Logger for the calling class.Returns a Logger with the name of the calling class. |
| public static Logger | |
| public static Logger | Returns: The Logger.The Class whose name should be used as the Logger name. If null it will default to the calling
class. clazz, final MessageFactory The message factory is used only when creating a logger, subsequent use does not change the
logger but will log a warning if mismatched. messageFactory)Returns a Logger using the fully qualified name of the Class as the Logger name. |
| public static Logger | Returns: The Logger for the calling class.The message factory is used only when creating a logger, subsequent use does not change the
logger but will log a warning if mismatched. messageFactory)Returns a Logger with the name of the calling class. |
| public static Logger | |
| public static Logger | Returns: The Logger.The value whose class name should be used as the Logger name. If null the name of the calling class
will be used as the logger name. value, final MessageFactory The message factory is used only when creating a logger, subsequent use does not change the
logger but will log a warning if mismatched. messageFactory)Returns a Logger using the fully qualified class name of the value as the Logger name. |
| public static Logger | |
| public static Logger | Returns: The Logger.The logger name. If null the name of the calling class will be used. name, final MessageFactory The message factory is used only when creating a logger, subsequent use does not change the
logger but will log a warning if mismatched. messageFactory)Returns a Logger with the specified name. |
| protected static Logger | |
| public static Logger | |
| public static void | setFactory(final LoggerContextFactory
the LoggerContextFactory to use. factory)Sets the current LoggerContextFactory to use. |
| public static void | |
| public static void | shutdown(final boolean
if true a default LoggerContext (may not be the LoggerContext used to create a Logger
for the calling class) will be used.
If false the LoggerContext appropriate for the caller of this method is used. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
used and if the caller is a class in the container's classpath then a different LoggerContext may
be used. currentContext)Shutdown the logging system if the logging system supports it. |
| public static void | shutdown(final boolean
if true a default LoggerContext (may not be the LoggerContext used to create a Logger
for the calling class) will be used.
If false the LoggerContext appropriate for the caller of this method is used. For
example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be
used and if the caller is a class in the container's classpath then a different LoggerContext may
be used. currentContext, final boolean if true all LoggerContexts that can be located will be shutdown. allContexts)Shutdown the logging system if the logging system supports it. |
| public static void | shutdown(final LoggerContext
the LoggerContext. context)Shutdown the logging system if the logging system supports it. |
| factory | back to summary |
|---|---|
| private static volatile LoggerContextFactory factory | |
| FACTORY_PROPERTY_NAME | back to summary |
|---|---|
| public static final String FACTORY_PROPERTY_NAME Log4j property to set to the fully qualified class name of a custom implementation of
| |
| FQCN | back to summary |
|---|---|
| private static final String FQCN | |
| LOGGER | back to summary |
|---|---|
| private static final Logger LOGGER | |
| ROOT_LOGGER_NAME | back to summary |
|---|---|
| public static final String ROOT_LOGGER_NAME The name of the root Logger is . | |
| LogManager | back to summary |
|---|---|
| protected LogManager() Prevents instantiation | |
| callerClass | back to summary |
|---|---|
| private static Class | |
| exists | back to summary |
|---|---|
| public static boolean exists(final String name) Detects if a Logger with the specified name exists. This is a convenience method for porting from version 1.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext() Returns the current LoggerContext. WARNING - The LoggerContext returned by this method may not be the LoggerContext used to create a Logger for the calling class.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext(final boolean currentContext) Returns a LoggerContext.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext) Returns a LoggerContext.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final Object externalContext) Returns a LoggerContext.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final URI configLocation) Returns a LoggerContext.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final Object externalContext, final URI configLocation) Returns a LoggerContext.
| |
| getContext | back to summary |
|---|---|
| public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final Object externalContext, final URI configLocation, final String name) Returns a LoggerContext.
| |
| getContext | back to summary |
|---|---|
| protected static LoggerContext getContext(final String fqcn, final boolean currentContext) Returns a LoggerContext
| |
| getContext | back to summary |
|---|---|
| protected static LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext) Returns a LoggerContext
| |
| getContext | back to summary |
|---|---|
| protected static LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext, final URI configLocation, final String name) Returns a LoggerContext
| |
| getFactory | back to summary |
|---|---|
| public static LoggerContextFactory getFactory() Returns the current LoggerContextFactory.
| |
| getFormatterLogger | back to summary |
|---|---|
| public static Logger getFormatterLogger() Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name.
This logger lets you use a
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger() Returns a Logger with the name of the calling class.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final Class<?> clazz) Returns a Logger using the fully qualified name of the Class as the Logger name.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final Class<?> clazz, final MessageFactory messageFactory) Returns a Logger using the fully qualified name of the Class as the Logger name.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final MessageFactory messageFactory) Returns a Logger with the name of the calling class.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final Object value) Returns a Logger using the fully qualified class name of the value as the Logger name.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final Object value, final MessageFactory messageFactory) Returns a Logger using the fully qualified class name of the value as the Logger name.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final String name) Returns a Logger with the specified name.
| |
| getLogger | back to summary |
|---|---|
| public static Logger getLogger(final String name, final MessageFactory messageFactory) Returns a Logger with the specified name.
| |
| getLogger | back to summary |
|---|---|
| protected static Logger getLogger(final String fqcn, final String name) Returns a Logger with the specified name. | |
| getRootLogger | back to summary |
|---|---|
| public static Logger getRootLogger() Returns the root logger.
| |
| setFactory | back to summary |
|---|---|
| public static void setFactory(final LoggerContextFactory factory) Sets the current LoggerContextFactory to use. Normally, the appropriate LoggerContextFactory is created at startup, but in certain environments, a LoggerContextFactory implementation may not be available at this point. Thus, an alternative LoggerContextFactory can be set at runtime. Note that any Logger or LoggerContext objects already created will still be valid, but they will no longer be accessible through LogManager. Thus, it is a bad idea to use this method without a good reason! Generally, this method should be used only during startup before any code starts caching Logger objects.
| |
| shutdown | back to summary |
|---|---|
| public static void shutdown() Shutdown using the LoggerContext appropriate for the caller of this method.
This is equivalent to calling
| |
| shutdown | back to summary |
|---|---|
| public static void shutdown(final boolean currentContext) Shutdown the logging system if the logging system supports it.
This is equivalent to calling
| |
| shutdown | back to summary |
|---|---|
| public static void shutdown(final boolean currentContext, final boolean allContexts) Shutdown the logging system if the logging system supports it.
This is equivalent to calling
| |
| shutdown | back to summary |
|---|---|
| public static void shutdown(final LoggerContext context) Shutdown the logging system if the logging system supports it. This call is synchronous and will block until shut down is complete. This may include flushing pending log events over network connections.
| |