Package org.apache.commons.logging.impl
Class Slf4jLogFactory
- java.lang.Object
-
- org.apache.commons.logging.LogFactory
-
- org.apache.commons.logging.impl.Slf4jLogFactory
-
public final class Slf4jLogFactory extends LogFactory
Logger factory hardcoded to send everything to SLF4J.- Since:
- 1.3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Slf4jLogFactory.Slf4jLocationAwareLog
private static class
Slf4jLogFactory.Slf4jLog
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>
attributes
private static java.lang.Object[]
EMPTY_OBJECT_ARRAY
private static java.lang.String[]
EMPTY_STRING_ARRAY
private java.util.concurrent.ConcurrentMap<java.lang.String,Log>
loggers
Caches Log instances.private static org.slf4j.Marker
MARKER
Marker used by all messages coming from Apache Commons Logging.-
Fields inherited from class org.apache.commons.logging.LogFactory
DIAGNOSTICS_DEST_PROPERTY, factories, FACTORY_DEFAULT, FACTORY_PROPERTIES, FACTORY_PROPERTY, HASHTABLE_IMPLEMENTATION_PROPERTY, nullClassLoaderFactory, PRIORITY_KEY, SERVICE_ID, TCCL_KEY
-
-
Constructor Summary
Constructors Constructor Description Slf4jLogFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getAttribute(java.lang.String name)
Return the configuration attribute with the specified name (if any), ornull
if there is no such attribute.java.lang.String[]
getAttributeNames()
Gets an array containing the names of all currently defined configuration attributes.Log
getInstance(java.lang.Class<?> clazz)
Convenience method to derive a name from the specified class and callgetInstance(String)
with it.Log
getInstance(java.lang.String name)
Constructs (if necessary) and return aLog
instance, using the factory's current set of configuration attributes.void
release()
This method is supposed to clear all loggers.void
removeAttribute(java.lang.String name)
Remove any configuration attribute associated with the specified name.void
setAttribute(java.lang.String name, java.lang.Object value)
Sets the configuration attribute with the specified name.-
Methods inherited from class org.apache.commons.logging.LogFactory
createFactory, directGetContextClassLoader, getClassLoader, getContextClassLoader, getFactory, getLog, getLog, handleThrowable, isDiagnosticsEnabled, logRawDiagnostic, newFactory, newFactory, objectId, release, releaseAll
-
-
-
-
Field Detail
-
EMPTY_OBJECT_ARRAY
private static final java.lang.Object[] EMPTY_OBJECT_ARRAY
-
EMPTY_STRING_ARRAY
private static final java.lang.String[] EMPTY_STRING_ARRAY
-
MARKER
private static final org.slf4j.Marker MARKER
Marker used by all messages coming from Apache Commons Logging.
-
loggers
private final java.util.concurrent.ConcurrentMap<java.lang.String,Log> loggers
Caches Log instances.The SLF4J reference implementation (Logback) has a single logger context, so each call to
getInstance(String)
should give the same result.
-
attributes
private final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> attributes
-
-
Method Detail
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from class:LogFactory
Return the configuration attribute with the specified name (if any), ornull
if there is no such attribute.- Specified by:
getAttribute
in classLogFactory
- Parameters:
name
- Name of the attribute to return- Returns:
- the configuration attribute with the specified name.
-
getAttributeNames
public java.lang.String[] getAttributeNames()
Description copied from class:LogFactory
Gets an array containing the names of all currently defined configuration attributes. If there are no such attributes, a zero length array is returned.- Specified by:
getAttributeNames
in classLogFactory
- Returns:
- an array containing the names of all currently defined configuration attributes
-
getInstance
public Log getInstance(java.lang.Class<?> clazz) throws LogConfigurationException
Description copied from class:LogFactory
Convenience method to derive a name from the specified class and callgetInstance(String)
with it.- Specified by:
getInstance
in classLogFactory
- Parameters:
clazz
- Class for which a suitable Log name will be derived- Returns:
- a name from the specified class.
- Throws:
LogConfigurationException
- if a suitableLog
instance cannot be returned
-
getInstance
public Log getInstance(java.lang.String name)
Description copied from class:LogFactory
Constructs (if necessary) and return aLog
instance, using the factory's current set of configuration attributes.NOTE - Depending upon the implementation of the
LogFactory
you are using, theLog
instance you are returned may or may not be local to the current application, and may or may not be returned again on a subsequent call with the same name argument.- Specified by:
getInstance
in classLogFactory
- Parameters:
name
- Logical name of theLog
instance to be returned (the meaning of this name is only known to the underlying logging implementation that is being wrapped)- Returns:
- a
Log
instance.
-
release
public void release()
This method is supposed to clear all loggers.In this implementation it calls a "stop" method if the logger factory supports it. This is the case of Logback.
- Specified by:
release
in classLogFactory
-
removeAttribute
public void removeAttribute(java.lang.String name)
Description copied from class:LogFactory
Remove any configuration attribute associated with the specified name. If there is no such attribute, no action is taken.- Specified by:
removeAttribute
in classLogFactory
- Parameters:
name
- Name of the attribute to remove
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Description copied from class:LogFactory
Sets the configuration attribute with the specified name. Calling this with anull
value is equivalent to callingremoveAttribute(name)
.- Specified by:
setAttribute
in classLogFactory
- Parameters:
name
- Name of the attribute to setvalue
- Value of the attribute to set, ornull
to remove any setting for this attribute
-
-