Class LogFactoryImpl
public class LogFactoryImpl extends LogFactory
Concrete subclass of 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.Logto identify the requested implementation class. - Use the
org.apache.commons.logging.Logsystem 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.
- Version:
- $Revision: 399224 $ $Date: 2006-05-03 10:25:54 +0100 (Wed, 03 May 2006) $
- Author:
- Rod Waldhoff, Craig R. McClanahan, Richard A. Sitze, Brian Stansberry
-
Field Summary
Fields Modifier and Type Field Description static StringALLOW_FLAWED_CONTEXT_PROPERTYThe name (org.apache.commons.logging.Log.allowFlawedContext) of the system property which can be set true/false to determine system behaviour when a bad context-classloader is encountered.static StringALLOW_FLAWED_DISCOVERY_PROPERTYThe name (org.apache.commons.logging.Log.allowFlawedDiscovery) of the system property which can be set true/false to determine system behaviour when a bad logging adapter class is encountered during logging discovery.static StringALLOW_FLAWED_HIERARCHY_PROPERTYThe name (org.apache.commons.logging.Log.allowFlawedHierarchy) of the system property which can be set true/false to determine system behaviour when a logging adapter class is encountered which has bound to the wrong Log class implementation.protected HashtableattributesConfiguration attributes.protected HashtableinstancesTheLoginstances that have already been created, keyed by logger name.static StringLOG_PROPERTYThe name (org.apache.commons.logging.Log) of the system property identifying ourLogimplementation class.protected static StringLOG_PROPERTY_OLDThe deprecated system property used for backwards compatibility with old versions of JCL.protected ConstructorlogConstructorThe one-argument constructor of theLogimplementation class that will be used to create new instances.protected Class[]logConstructorSignatureThe signature of the Constructor to be used.protected MethodlogMethodThe one-argumentsetLogFactorymethod of the selectedLogmethod, if it exists.protected Class[]logMethodSignatureThe signature of thesetLogFactorymethod 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
Constructors Constructor Description LogFactoryImpl()Public no-arguments constructor required by the lookup mechanism. -
Method Summary
Modifier and Type Method Description ObjectgetAttribute(String name)Return the configuration attribute with the specified name (if any), ornullif there is no such attribute.String[]getAttributeNames()Return an array containing the names of all currently defined configuration attributes.protected static ClassLoadergetClassLoader(Class clazz)Workaround for bug in Java1.2; in theory this method is not needed.protected static ClassLoadergetContextClassLoader()Gets the context classloader.LoggetInstance(Class clazz)Convenience method to derive a name from the specified class and callgetInstance(String)with it.LoggetInstance(String name)Construct (if necessary) and return aLoginstance, using the factory's current set of configuration attributes.protected StringgetLogClassName()Deprecated.Never invoked by this class; subclasses should not assume it will be.protected ConstructorgetLogConstructor()Deprecated.Never invoked by this class; subclasses should not assume it will be.protected static booleanisDiagnosticsEnabled()Workaround for bug in Java1.2; in theory this method is not needed.protected booleanisJdk13LumberjackAvailable()Deprecated.Never invoked by this class; subclasses should not assume it will be.protected booleanisJdk14Available()Deprecated.Never invoked by this class; subclasses should not assume it will be.protected booleanisLog4JAvailable()Deprecated.Never invoked by this class; subclasses should not assume it will be.protected voidlogDiagnostic(String msg)Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).protected LognewInstance(String name)Create and return a newLoginstance for the specified name.voidrelease()Release any internal references to previously createdLoginstances returned by this factory.voidremoveAttribute(String name)Remove any configuration attribute associated with the specified name.voidsetAttribute(String name, Object value)Set the configuration attribute with the specified name.Methods inherited from class org.apache.commons.logging.LogFactory
createFactory, directGetContextClassLoader, getFactory, getLog, getLog, logRawDiagnostic, newFactory, newFactory, objectId, release, releaseAll
-
Field Details
-
LOG_PROPERTY
The name (org.apache.commons.logging.Log) of the system property identifying ourLogimplementation class.- See Also:
- Constant Field Values
-
LOG_PROPERTY_OLD
The deprecated system property used for backwards compatibility with old versions of JCL.- See Also:
- Constant Field Values
-
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 behaviour when a bad context-classloader is encountered. When set to false, a LogConfigurationException is thrown if LogFactoryImpl is loaded via a child classloader of the TCCL (this should never happen in sane systems). Default behaviour: true (tolerates bad context classloaders) See also method setAttribute.- See Also:
- Constant Field Values
-
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 behaviour 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 behaviour: true (tolerates bad logging adapters) See also method setAttribute.- See Also:
- Constant Field Values
-
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 behaviour 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 behaviour: true (tolerates bad Log class hierarchy) See also method setAttribute.- See Also:
- Constant Field Values
-
attributes
Configuration attributes. -
instances
TheLoginstances that have already been created, keyed by logger name. -
logConstructor
The one-argument constructor of theLogimplementation 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-argumentsetLogFactorymethod of the selectedLogmethod, if it exists. -
logMethodSignature
The signature of thesetLogFactorymethod to be used.
-
-
Constructor Details
-
LogFactoryImpl
public LogFactoryImpl()Public no-arguments constructor required by the lookup mechanism.
-
-
Method Details
-
getAttribute
Return the configuration attribute with the specified name (if any), ornullif there is no such attribute.- Specified by:
getAttributein classLogFactory- Parameters:
name- Name of the attribute to return
-
getAttributeNames
Return 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:
getAttributeNamesin classLogFactory
-
getInstance
Convenience method to derive a name from the specified class and callgetInstance(String)with it.- Specified by:
getInstancein classLogFactory- Parameters:
clazz- Class for which a suitable Log name will be derived- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
getInstance
Construct (if necessary) and return a
Loginstance, using the factory's current set of configuration attributes.NOTE - Depending upon the implementation of the
LogFactoryyou are using, theLoginstance 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:
getInstancein classLogFactory- Parameters:
name- Logical name of theLoginstance to be returned (the meaning of this name is only known to the underlying logging implementation that is being wrapped)- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
release
public void release()Release any internal references to previously createdLoginstances 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:
releasein classLogFactory
-
removeAttribute
Remove any configuration attribute associated with the specified name. If there is no such attribute, no action is taken.- Specified by:
removeAttributein classLogFactory- Parameters:
name- Name of the attribute to remove
-
setAttribute
Set the configuration attribute with the specified name. Calling this with anullvalue 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 behaviour 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:
setAttributein classLogFactory- Parameters:
name- Name of the attribute to setvalue- Value of the attribute to set, ornullto remove any setting for this attribute
-
getContextClassLoader
Gets the context classloader. This method is a workaround for a java 1.2 compiler bug.- Throws:
LogConfigurationException- Since:
- 1.1
-
isDiagnosticsEnabled
protected static boolean isDiagnosticsEnabled()Workaround for bug in Java1.2; in theory this method is not needed. See LogFactory.isDiagnosticsEnabled. -
getClassLoader
Workaround for bug in Java1.2; in theory this method is not needed. See LogFactory.getClassLoader.- Since:
- 1.1
-
logDiagnostic
Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).- Parameters:
msg- diagnostic message- Since:
- 1.1
-
getLogClassName
Deprecated.Never invoked by this class; subclasses should not assume it will be.Return the fully qualified Java classname of theLogimplementation we will be using. -
getLogConstructor
Deprecated.Never invoked by this class; subclasses should not assume it will be.Return the
Constructorthat can be called to instantiate newLoginstances.IMPLEMENTATION NOTE - Race conditions caused by calling this method from more than one thread are ignored, because the same
Constructorinstance will ultimately be derived in all circumstances.- Throws:
LogConfigurationException- if a suitable constructor cannot be returned
-
isJdk13LumberjackAvailable
protected boolean isJdk13LumberjackAvailable()Deprecated.Never invoked by this class; subclasses should not assume it will be.Is JDK 1.3 with Lumberjack logging available? -
isJdk14Available
protected boolean isJdk14Available()Deprecated.Never invoked by this class; subclasses should not assume it will be.Return
trueif JDK 1.4 or later logging is available. Also checks that theThrowableclass supportsgetStackTrace(), which is required by Jdk14Logger. -
isLog4JAvailable
protected boolean isLog4JAvailable()Deprecated.Never invoked by this class; subclasses should not assume it will be.Is a Log4J implementation available? -
newInstance
Create and return a newLoginstance for the specified name.- Parameters:
name- Name of the new logger- Throws:
LogConfigurationException- if a new instance cannot be created
-