org.apache.commons.logging.impl
public class LogFactoryImpl extends LogFactory
Concrete subclass of {@link LogFactory} that implements the following algorithm to dynamically select a logging implementation class to instantiate a wrapper for.
org.apache.commons.logging.Log
to identify the
requested implementation class.org.apache.commons.logging.Log
system property
to identify the requested implementation class.org.apache.commons.logging.impl.Log4JLogger
.org.apache.commons.logging.impl.Jdk14Logger
.org.apache.commons.logging.impl.SimpleLog
.If the selected {@link Log} implementation class has a
setLogFactory()
method that accepts a {@link LogFactory}
parameter, this method will be called on each newly created instance
to identify the associated factory. This makes factory configuration
attributes available to the Log instance, if it so desires.
This factory will remember previously created Log
instances
for the same name, and will return them on repeated requests to the
getInstance()
method. This implementation ignores any
configured attributes.
Version: $Revision: 1.33 $ $Date: 2004/03/06 21:52:59 $
Field Summary | |
---|---|
protected Hashtable | attributes
Configuration attributes. |
protected Hashtable | instances
The {@link org.apache.commons.logging.Log} instances that have
already been created, keyed by logger name. |
String | logClassName
Name of the class implementing the Log interface. |
protected Constructor | logConstructor
The one-argument constructor of the
{@link org.apache.commons.logging.Log}
implementation class that will be used to create new instances.
|
protected Class[] | logConstructorSignature
The signature of the Constructor to be used. |
protected Method | logMethod
The one-argument setLogFactory method of the selected
{@link org.apache.commons.logging.Log} method, if it exists. |
protected Class[] | logMethodSignature
The signature of the setLogFactory method to be used. |
static String | LOG_INTERFACE The name of the {@link Log} interface class. |
static String | LOG_PROPERTY
The name of the system property identifying our {@link Log}
implementation class. |
protected static String | LOG_PROPERTY_OLD
The deprecated system property used for backwards compatibility with
the old {@link org.apache.commons.logging.LogSource} class. |
Constructor Summary | |
---|---|
LogFactoryImpl()
Public no-arguments constructor required by the lookup mechanism. |
Method Summary | |
---|---|
Object | getAttribute(String name)
Return the configuration attribute with the specified name (if any),
or null if there is no such attribute.
|
String[] | getAttributeNames()
Return an array containing the names of all currently defined
configuration attributes. |
Log | getInstance(Class clazz)
Convenience method to derive a name from the specified class and
call getInstance(String) with it.
|
Log | getInstance(String name) Construct (if necessary) and return a NOTE - Depending upon the implementation of
the |
protected String | getLogClassName()
Return the fully qualified Java classname of the {@link Log}
implementation we will be using. |
protected Constructor | getLogConstructor() Return the IMPLEMENTATION NOTE - Race conditions caused by
calling this method from more than one thread are ignored, because
the same |
protected boolean | isJdk13LumberjackAvailable()
Is JDK 1.3 with Lumberjack logging available? |
protected boolean | isJdk14Available() Return |
protected boolean | isLog4JAvailable()
Is a Log4J implementation available? |
static Class | loadClass(String name)
MUST KEEP THIS METHOD PRIVATE.
|
protected Log | newInstance(String name)
Create and return a new {@link org.apache.commons.logging.Log}
instance for the specified name.
|
void | release()
Release any internal references to previously created
{@link org.apache.commons.logging.Log}
instances returned by this factory. |
void | removeAttribute(String name)
Remove any configuration attribute associated with the specified name.
|
void | setAttribute(String name, Object value)
Set the configuration attribute with the specified name. |
getLogConstructor()
,
and then returned repeatedly.setLogFactory
method of the selected
{@link org.apache.commons.logging.Log} method, if it exists.setLogFactory
method to be used.The name of the {@link Log} interface class.
null
if there is no such attribute.
Parameters: name Name of the attribute to return
getInstance(String)
with it.
Parameters: clazz Class for which a suitable Log name will be derived
Throws: LogConfigurationException if a suitable Log
instance cannot be returned
Construct (if necessary) and return a Log
instance,
using the factory's current set of configuration attributes.
NOTE - Depending upon the implementation of
the LogFactory
you are using, the Log
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.
Parameters: name Logical name of the Log
instance to be
returned (the meaning of this name is only known to the underlying
logging implementation that is being wrapped)
Throws: LogConfigurationException if a suitable Log
instance cannot be returned
Return the Constructor
that can be called to instantiate
new {@link org.apache.commons.logging.Log} instances.
IMPLEMENTATION NOTE - Race conditions caused by
calling this method from more than one thread are ignored, because
the same Constructor
instance will ultimately be derived
in all circumstances.
Throws: LogConfigurationException if a suitable constructor cannot be returned
Return true
if JDK 1.4 or later logging
is available. Also checks that the Throwable
class
supports getStackTrace()
, which is required by
Jdk14Logger.
Exposing this method outside of
org.apache.commons.logging.LogFactoryImpl
will create a security violation:
This method uses AccessController.doPrivileged()
.
Parameters: name Name of the new logger
Throws: LogConfigurationException if a new instance cannot be created
Parameters: name Name of the attribute to remove
null
value is equivalent to calling
removeAttribute(name)
.
Parameters: name Name of the attribute to set value Value of the attribute to set, or null
to remove any setting for this attribute