Class LogFactoryImpl
LogFactory
that implements the
following algorithm to dynamically select a logging implementation
class to instantiate a wrapper for:
- Use a factory configuration attribute named
org.apache.commons.logging.Log
to identify the requested implementation class. - Use the
org.apache.commons.logging.Log
system property to identify the requested implementation class. - If Log4J is available, return an instance of
org.apache.commons.logging.impl.Log4JLogger
. - If JDK 1.4 or later is available, return an instance of
org.apache.commons.logging.impl.Jdk14Logger
. - Otherwise, return an instance of
org.apache.commons.logging.impl.SimpleLog
.
If the selected Log
implementation class has a
setLogFactory()
method that accepts a 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.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name (org.apache.commons.logging.Log.allowFlawedContext
) of the system property which can be set true/false to determine system behavior when a bad context class loader is encountered.static final String
The name (org.apache.commons.logging.Log.allowFlawedDiscovery
) of the system property which can be set true/false to determine system behavior when a bad logging adapter class is encountered during logging discovery.static final String
The name (org.apache.commons.logging.Log.allowFlawedHierarchy
) of the system property which can be set true/false to determine system behavior when a logging adapter class is encountered which has bound to the wrong Log class implementation.Configuration attributes.TheLog
instances that have already been created, keyed by logger name.static final String
The name (org.apache.commons.logging.Log
) of the system property identifying ourLog
implementation class.protected static final String
The deprecated system property used for backwards compatibility with old versions of JCL.protected Constructor<?>
The one-argument constructor of theLog
implementation class that will be used to create new instances.protected Class<?>[]
The signature of the Constructor to be used.protected Method
The one-argumentsetLogFactory
method of the selectedLog
method, if it exists.protected Class<?>[]
The signature of thesetLogFactory
method to be used.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
ConstructorDescriptionPublic no-arguments constructor required by the lookup mechanism. -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute
(String name) Gets the configuration attribute with the specified name (if any), ornull
if there is no such attribute.String[]
Gets an array containing the names of all currently defined configuration attributes.protected static ClassLoader
getClassLoader
(Class<?> clazz) Workaround for bug in Java1.2; in theory this method is not needed.protected static ClassLoader
Gets the context ClassLoader.getInstance
(Class<?> clazz) Convenience method to derive a name from the specified class and callgetInstance(String)
with it.getInstance
(String name) Construct (if necessary) and return aLog
instance, using the factory's current set of configuration attributes.protected String
Deprecated.Never invoked by this class; subclasses should not assume it will be.protected Constructor<?>
Deprecated.Never invoked by this class; subclasses should not assume it will be.protected static boolean
Workaround for bug in Java1.2; in theory this method is not needed.protected boolean
Deprecated.Never invoked by this class; subclasses should not assume it will be.protected boolean
Deprecated.Never invoked by this class; subclasses should not assume it will be.protected boolean
Deprecated.Never invoked by this class; subclasses should not assume it will be.protected void
logDiagnostic
(String msg) Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).protected Log
newInstance
(String name) Create and return a newLog
instance for the specified name.void
release()
Release any internal references to previously createdLog
instances returned by this factory.void
removeAttribute
(String name) Remove any configuration attribute associated with the specified name.void
setAttribute
(String name, Object value) Sets the configuration attribute with the specified name.Methods inherited from class org.apache.commons.logging.LogFactory
createFactory, directGetContextClassLoader, getFactory, getLog, getLog, handleThrowable, logRawDiagnostic, newFactory, newFactory, objectId, release, releaseAll
-
Field Details
-
LOG_PROPERTY
The name (org.apache.commons.logging.Log
) of the system property identifying ourLog
implementation class.- See Also:
-
LOG_PROPERTY_OLD
The deprecated system property used for backwards compatibility with old versions of JCL.- See Also:
-
ALLOW_FLAWED_CONTEXT_PROPERTY
The name (org.apache.commons.logging.Log.allowFlawedContext
) of the system property which can be set true/false to determine system behavior when a bad context class loader is encountered. When set to false, a LogConfigurationException is thrown if LogFactoryImpl is loaded via a child class loader of the TCCL (this should never happen in sane systems). Default behavior: true (tolerates bad context class loaders) See also method setAttribute.- See Also:
-
ALLOW_FLAWED_DISCOVERY_PROPERTY
The name (org.apache.commons.logging.Log.allowFlawedDiscovery
) of the system property which can be set true/false to determine system behavior when a bad logging adapter class is encountered during logging discovery. When set to false, an exception will be thrown and the app will fail to start. When set to true, discovery will continue (though the user might end up with a different logging implementation than they expected).Default behavior: true (tolerates bad logging adapters) See also method setAttribute.
- See Also:
-
ALLOW_FLAWED_HIERARCHY_PROPERTY
The name (org.apache.commons.logging.Log.allowFlawedHierarchy
) of the system property which can be set true/false to determine system behavior when a logging adapter class is encountered which has bound to the wrong Log class implementation. When set to false, an exception will be thrown and the app will fail to start. When set to true, discovery will continue (though the user might end up with a different logging implementation than they expected).Default behavior: true (tolerates bad Log class hierarchy) See also method setAttribute.
- See Also:
-
attributes
Configuration attributes. -
instances
TheLog
instances that have already been created, keyed by logger name. -
logConstructor
The one-argument constructor of theLog
implementation class that will be used to create new instances. This value is initialized bygetLogConstructor()
, and then returned repeatedly. -
logConstructorSignature
The signature of the Constructor to be used. -
logMethod
The one-argumentsetLogFactory
method of the selectedLog
method, if it exists. -
logMethodSignature
The signature of thesetLogFactory
method to be used.
-
-
Constructor Details
-
LogFactoryImpl
public LogFactoryImpl()Public no-arguments constructor required by the lookup mechanism.
-
-
Method Details
-
getClassLoader
Workaround for bug in Java1.2; in theory this method is not needed.LogFactory.getClassLoader(Class)
.- Parameters:
clazz
- SeeLogFactory.getClassLoader(Class)
.- Returns:
- See
LogFactory.getClassLoader(Class)
. - Since:
- 1.1
-
getContextClassLoader
Gets the context ClassLoader. This method is a workaround for a Java 1.2 compiler bug.- Returns:
- the context ClassLoader
- Throws:
LogConfigurationException
- Since:
- 1.1
-
isDiagnosticsEnabled
Workaround for bug in Java1.2; in theory this method is not needed.- Returns:
- Same as
LogFactory.isDiagnosticsEnabled()
. - See Also:
-
getAttribute
Gets 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
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
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
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, 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. - Throws:
LogConfigurationException
- if a suitableLog
instance cannot be returned
-
getLogClassName
Deprecated.Never invoked by this class; subclasses should not assume it will be.Gets the fully qualified Java class name of theLog
implementation we will be using.- Returns:
- the fully qualified Java class name of the
Log
implementation we will be using.
-
getLogConstructor
Deprecated.Never invoked by this class; subclasses should not assume it will be.Gets the
Constructor
that can be called to instantiate newLog
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.- Returns:
- the
Constructor
that can be called to instantiate newLog
instances. - Throws:
LogConfigurationException
- if a suitable constructor cannot be returned
-
isJdk13LumberjackAvailable
Deprecated.Never invoked by this class; subclasses should not assume it will be.Tests whether JDK 1.3 with Lumberjack logging available.- Returns:
- whether JDK 1.3 with Lumberjack logging available.
-
isJdk14Available
Deprecated.Never invoked by this class; subclasses should not assume it will be.Teststrue
whether JDK 1.4 or later logging is available. Also checks that theThrowable
class supportsgetStackTrace()
, which is required by Jdk14Logger.- Returns:
- Whether JDK 1.4 or later logging is available.
-
isLog4JAvailable
Deprecated.Never invoked by this class; subclasses should not assume it will be.Tests whether a Log4J implementation available.- Returns:
- whether a Log4J implementation available.
-
logDiagnostic
Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).- Parameters:
msg
- diagnostic message- Since:
- 1.1
-
newInstance
Create and return a newLog
instance for the specified name.- Parameters:
name
- Name of the new logger- Returns:
- a new
Log
- Throws:
LogConfigurationException
- if a new instance cannot be created
-
release
Release any internal references to previously createdLog
instances returned by this factory. This is useful in environments like servlet containers, which implement application reloading by throwing away a ClassLoader. Dangling references to objects in that class loader would prevent garbage collection.- Specified by:
release
in classLogFactory
-
removeAttribute
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
Sets the configuration attribute with the specified name. Calling this with anull
value is equivalent to callingremoveAttribute(name)
.This method can be used to set logging configuration programmatically rather than via system properties. It can also be used in code running within a container (such as a webapp) to configure behavior on a per-component level instead of globally as system properties would do. To use this method instead of a system property, call
LogFactory.getFactory().setAttribute(...)
This must be done before the first Log object is created; configuration changes after that point will be ignored.This method is also called automatically if LogFactory detects a commons-logging.properties file; every entry in that file is set automatically as an attribute here.
- 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
-