Class LogFactoryImpl
- java.lang.Object
-
- org.apache.commons.logging.LogFactory
-
- org.apache.commons.logging.impl.LogFactoryImpl
-
public class LogFactoryImpl extends LogFactory
Concrete subclass ofLogFactorythat 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
Logimplementation class has asetLogFactory()method that accepts aLogFactoryparameter, 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
Loginstances for the same name, and will return them on repeated requests to thegetInstance()method. - Use a factory configuration attribute named
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALLOW_FLAWED_CONTEXT_PROPERTYThe 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 java.lang.StringALLOW_FLAWED_DISCOVERY_PROPERTYThe 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 java.lang.StringALLOW_FLAWED_HIERARCHY_PROPERTYThe 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.private booleanallowFlawedContextSee getBaseClassLoader and initConfiguration.private booleanallowFlawedDiscoverySee handleFlawedDiscovery and initConfiguration.private booleanallowFlawedHierarchySee handleFlawedHierarchy and initConfiguration.protected java.util.Hashtable<java.lang.String,java.lang.Object>attributesConfiguration attributes.private java.lang.StringdiagnosticPrefixThe string prefixed to every message output by the logDiagnostic method.private static java.lang.String[]DISCOVER_CLASSESThe names of classes that will be tried (in order) as logging adapters.private static java.lang.String[]EMPTY_STRING_ARRAYAn empty immutableStringarray.protected java.util.Hashtable<java.lang.String,Log>instancesTheLoginstances that have already been created, keyed by logger name.static java.lang.StringLOG_PROPERTYThe name (org.apache.commons.logging.Log) of the system property identifying ourLogimplementation class.protected static java.lang.StringLOG_PROPERTY_OLDThe deprecated system property used for backwards compatibility with old versions of JCL.private java.lang.StringlogClassNameName of the class implementing the Log interface.protected java.lang.reflect.Constructor<?>logConstructorThe one-argument constructor of theLogimplementation class that will be used to create new instances.protected java.lang.Class<?>[]logConstructorSignatureThe signature of the Constructor to be used.private static java.lang.StringLOGGING_IMPL_JDK14_LOGGERJdk14Logger class nameprivate static java.lang.StringLOGGING_IMPL_LOG4J_LOGGERLog4JLogger class nameprivate static java.lang.StringLOGGING_IMPL_LUMBERJACK_LOGGERJdk13LumberjackLogger class nameprivate static java.lang.StringLOGGING_IMPL_SIMPLE_LOGGERSimpleLog class nameprotected java.lang.reflect.MethodlogMethodThe one-argumentsetLogFactorymethod of the selectedLogmethod, if it exists.protected java.lang.Class<?>[]logMethodSignatureThe signature of thesetLogFactorymethod to be used.private static java.lang.StringPKG_IMPLprivate static intPKG_LENprivate booleanuseTCCLDetermines whether logging classes should be loaded using the thread-context class loader, or via the class loader that loaded this LogFactoryImpl class.-
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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private LogcreateLogFromClass(java.lang.String logAdapterClassName, java.lang.String logCategory, boolean affectState)Attempts to load the given class, find a suitable constructor, and instantiate an instance of Log.private LogdiscoverLogImplementation(java.lang.String logCategory)Attempts to create a Log instance for the given category name.private java.lang.StringfindUserSpecifiedLogClassName()Checks system properties and the attribute map for a Log implementation specified by the user under the property namesLOG_PROPERTYorLOG_PROPERTY_OLD.java.lang.ObjectgetAttribute(java.lang.String name)Gets the configuration attribute with the specified name (if any), ornullif there is no such attribute.java.lang.String[]getAttributeNames()Gets an array containing the names of all currently defined configuration attributes.private java.lang.ClassLoadergetBaseClassLoader()Gets the class loader from which we should try to load the logging adapter classes.private booleangetBooleanConfiguration(java.lang.String key, boolean dflt)Gets the setting for the user-configurable behavior specified by key.protected static java.lang.ClassLoadergetClassLoader(java.lang.Class<?> clazz)Workaround for bug in Java1.2; in theory this method is not needed.private java.lang.StringgetConfigurationValue(java.lang.String property)Attempt to find an attribute (see method setAttribute) or a system property with the provided name and return its value.protected static java.lang.ClassLoadergetContextClassLoader()Gets the context ClassLoader.private static java.lang.ClassLoadergetContextClassLoaderInternal()Calls LogFactory.directGetContextClassLoader under the control of an AccessController class.LoggetInstance(java.lang.Class<?> clazz)Convenience method to derive a name from the specified class and callgetInstance(String)with it.LoggetInstance(java.lang.String name)Construct (if necessary) and return aLoginstance, using the factory's current set of configuration attributes.protected java.lang.StringgetLogClassName()Deprecated.Never invoked by this class; subclasses should not assume it will be.protected java.lang.reflect.Constructor<?>getLogConstructor()Deprecated.Never invoked by this class; subclasses should not assume it will be.private java.lang.ClassLoadergetLowestClassLoader(java.lang.ClassLoader c1, java.lang.ClassLoader c2)Given two related class loaders, return the one which is a child of the other.private java.lang.ClassLoadergetParentClassLoader(java.lang.ClassLoader cl)Fetch the parent class loader of a specified class loader.private static java.lang.StringgetSystemProperty(java.lang.String key, java.lang.String def)Reads the specified system property, using an AccessController so that the property can be read if JCL has been granted the appropriate security rights even if the calling code has not.private voidhandleFlawedDiscovery(java.lang.String logAdapterClassName, java.lang.Throwable discoveryFlaw)Generates an internal diagnostic logging of the discovery failure and then throws aLogConfigurationExceptionthat wraps the passedThrowable.private voidhandleFlawedHierarchy(java.lang.ClassLoader badClassLoader, java.lang.Class<?> badClass)Report a problem loading the log adapter, then either return (if the situation is considered recoverable) or throw a LogConfigurationException.private voidinformUponSimilarName(java.lang.StringBuilder messageBuffer, java.lang.String name, java.lang.String candidate)Appends message if the given name is similar to the candidate.private voidinitConfiguration()Initializes a number of variables that control the behavior of this class and that can be tweaked by the user.private voidinitDiagnostics()Initializes a string that uniquely identifies this instance, including which class loader the object was loaded from.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.private booleanisLogLibraryAvailable(java.lang.String name, java.lang.String className)Tests whether a particular logging library is present and available for use.protected voidlogDiagnostic(java.lang.String msg)Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).protected LognewInstance(java.lang.String name)Create and return a newLoginstance for the specified name.voidrelease()Releases any internal references to previously createdLoginstances returned by this factory.voidremoveAttribute(java.lang.String name)Remove any configuration attribute associated with the specified name.voidsetAttribute(java.lang.String name, java.lang.Object value)Sets the configuration attribute with the specified name.private static java.lang.Stringtrim(java.lang.String src)Utility method to safely trim a string.-
Methods inherited from class org.apache.commons.logging.LogFactory
createFactory, directGetContextClassLoader, getFactory, getLog, getLog, handleThrowable, logRawDiagnostic, newFactory, newFactory, objectId, release, releaseAll
-
-
-
-
Field Detail
-
LOGGING_IMPL_LOG4J_LOGGER
private static final java.lang.String LOGGING_IMPL_LOG4J_LOGGER
Log4JLogger class name- See Also:
- Constant Field Values
-
LOGGING_IMPL_JDK14_LOGGER
private static final java.lang.String LOGGING_IMPL_JDK14_LOGGER
Jdk14Logger class name- See Also:
- Constant Field Values
-
LOGGING_IMPL_LUMBERJACK_LOGGER
private static final java.lang.String LOGGING_IMPL_LUMBERJACK_LOGGER
Jdk13LumberjackLogger class name- See Also:
- Constant Field Values
-
LOGGING_IMPL_SIMPLE_LOGGER
private static final java.lang.String LOGGING_IMPL_SIMPLE_LOGGER
SimpleLog class name- See Also:
- Constant Field Values
-
PKG_IMPL
private static final java.lang.String PKG_IMPL
- See Also:
- Constant Field Values
-
PKG_LEN
private static final int PKG_LEN
-
EMPTY_STRING_ARRAY
private static final java.lang.String[] EMPTY_STRING_ARRAY
An empty immutableStringarray.
-
LOG_PROPERTY
public static final java.lang.String LOG_PROPERTY
The name (org.apache.commons.logging.Log) of the system property identifying ourLogimplementation class.- See Also:
- Constant Field Values
-
LOG_PROPERTY_OLD
protected static final java.lang.String 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
public static final java.lang.String 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:
- Constant Field Values
-
ALLOW_FLAWED_DISCOVERY_PROPERTY
public static final java.lang.String 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:
- Constant Field Values
-
ALLOW_FLAWED_HIERARCHY_PROPERTY
public static final java.lang.String 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:
- Constant Field Values
-
DISCOVER_CLASSES
private static final java.lang.String[] DISCOVER_CLASSES
The names of classes that will be tried (in order) as logging adapters. Each class is expected to implement the Log interface, and to throw NoClassDefFound or ExceptionInInitializerError when loaded if the underlying logging library is not available. Any other error indicates that the underlying logging library is available but broken/unusable for some reason.
-
useTCCL
private boolean useTCCL
Determines whether logging classes should be loaded using the thread-context class loader, or via the class loader that loaded this LogFactoryImpl class.
-
diagnosticPrefix
private java.lang.String diagnosticPrefix
The string prefixed to every message output by the logDiagnostic method.
-
attributes
protected java.util.Hashtable<java.lang.String,java.lang.Object> attributes
Configuration attributes.
-
instances
protected java.util.Hashtable<java.lang.String,Log> instances
TheLoginstances that have already been created, keyed by logger name.
-
logClassName
private java.lang.String logClassName
Name of the class implementing the Log interface.
-
logConstructor
protected java.lang.reflect.Constructor<?> 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
protected java.lang.Class<?>[] logConstructorSignature
The signature of the Constructor to be used.
-
logMethod
protected java.lang.reflect.Method logMethod
The one-argumentsetLogFactorymethod of the selectedLogmethod, if it exists.
-
logMethodSignature
protected java.lang.Class<?>[] logMethodSignature
The signature of thesetLogFactorymethod to be used.
-
allowFlawedContext
private boolean allowFlawedContext
See getBaseClassLoader and initConfiguration.
-
allowFlawedDiscovery
private boolean allowFlawedDiscovery
See handleFlawedDiscovery and initConfiguration.
-
allowFlawedHierarchy
private boolean allowFlawedHierarchy
See handleFlawedHierarchy and initConfiguration.
-
-
Method Detail
-
getClassLoader
protected static java.lang.ClassLoader getClassLoader(java.lang.Class<?> clazz)
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
protected static java.lang.ClassLoader getContextClassLoader() throws LogConfigurationExceptionGets the context ClassLoader. This method is a workaround for a Java 1.2 compiler bug.- Returns:
- the context ClassLoader
- Throws:
LogConfigurationException- Since:
- 1.1
-
getContextClassLoaderInternal
private static java.lang.ClassLoader getContextClassLoaderInternal() throws LogConfigurationExceptionCalls LogFactory.directGetContextClassLoader under the control of an AccessController class. This means that Java code running under a security manager that forbids access to ClassLoaders will still work if this class is given appropriate privileges, even when the caller doesn't have such privileges. Without using an AccessController, the the entire call stack must have the privilege before the call is allowed.- Returns:
- the context class loader associated with the current thread, or null if security doesn't allow it.
- Throws:
LogConfigurationException- if there was some weird error while attempting to get the context class loader.java.lang.SecurityException- if the current Java security policy doesn't allow this class to access the context class loader.
-
getSystemProperty
private static java.lang.String getSystemProperty(java.lang.String key, java.lang.String def) throws java.lang.SecurityExceptionReads the specified system property, using an AccessController so that the property can be read if JCL has been granted the appropriate security rights even if the calling code has not.Take care not to expose the value returned by this method to the calling application in any way; otherwise the calling app can use that info to access data that should not be available to it.
- Throws:
java.lang.SecurityException
-
isDiagnosticsEnabled
protected static boolean isDiagnosticsEnabled()
Workaround for bug in Java1.2; in theory this method is not needed.- Returns:
- Same as
LogFactory.isDiagnosticsEnabled(). - See Also:
LogFactory.isDiagnosticsEnabled()
-
trim
private static java.lang.String trim(java.lang.String src)
Utility method to safely trim a string.
-
createLogFromClass
private Log createLogFromClass(java.lang.String logAdapterClassName, java.lang.String logCategory, boolean affectState) throws LogConfigurationException
Attempts to load the given class, find a suitable constructor, and instantiate an instance of Log.- Parameters:
logAdapterClassName- class name of the Log implementationlogCategory- argument to pass to the Log implementation's constructoraffectState-trueif this object's state should be affected by this method call,falseotherwise.- Returns:
- an instance of the given class, or null if the logging library associated with the specified adapter is not available.
- Throws:
LogConfigurationException- if there was a serious error with configuration and the handleFlawedDiscovery method decided this problem was fatal.
-
discoverLogImplementation
private Log discoverLogImplementation(java.lang.String logCategory) throws LogConfigurationException
Attempts to create a Log instance for the given category name. Follows the discovery process described in the class Javadoc.- Parameters:
logCategory- the name of the log category- Throws:
LogConfigurationException- if an error in discovery occurs, or if no adapter at all can be instantiated
-
findUserSpecifiedLogClassName
private java.lang.String findUserSpecifiedLogClassName()
Checks system properties and the attribute map for a Log implementation specified by the user under the property namesLOG_PROPERTYorLOG_PROPERTY_OLD.- Returns:
- class name specified by the user, or
null
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Gets 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- Returns:
- the configuration attribute with the specified name.
-
getAttributeNames
public java.lang.String[] 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:
getAttributeNamesin classLogFactory- Returns:
- an array containing the names of all currently defined configuration attributes
-
getBaseClassLoader
private java.lang.ClassLoader getBaseClassLoader() throws LogConfigurationExceptionGets the class loader from which we should try to load the logging adapter classes.This method usually returns the context class loader. However if it is discovered that the class loader which loaded this class is a child of the context class loader and the allowFlawedContext option has been set then the class loader which loaded this class is returned instead.
The only time when the class loader which loaded this class is a descendant (rather than the same as or an ancestor of the context class loader) is when an app has created custom class loaders but failed to correctly set the context class loader. This is a bug in the calling application; however we provide the option for JCL to simply generate a warning rather than fail outright.
- Throws:
LogConfigurationException
-
getBooleanConfiguration
private boolean getBooleanConfiguration(java.lang.String key, boolean dflt)Gets the setting for the user-configurable behavior specified by key. If nothing has explicitly been set, then return dflt.
-
getConfigurationValue
private java.lang.String getConfigurationValue(java.lang.String property)
Attempt to find an attribute (see method setAttribute) or a system property with the provided name and return its value.The attributes associated with this object are checked before system properties in case someone has explicitly called setAttribute, or a configuration property has been set in a commons-logging.properties file.
- Returns:
- the value associated with the property, or null.
-
getInstance
public Log getInstance(java.lang.Class<?> clazz) throws LogConfigurationException
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- Returns:
- a name from the specified class.
- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
getInstance
public Log getInstance(java.lang.String name) throws LogConfigurationException
Construct (if necessary) and return aLoginstance, 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)- Returns:
- a
Loginstance. - Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
getLogClassName
@Deprecated protected java.lang.String getLogClassName()
Deprecated.Never invoked by this class; subclasses should not assume it will be.Gets the fully qualified Java class name of theLogimplementation we will be using.- Returns:
- the fully qualified Java class name of the
Logimplementation we will be using.
-
getLogConstructor
@Deprecated protected java.lang.reflect.Constructor<?> getLogConstructor() throws LogConfigurationExceptionDeprecated.Never invoked by this class; subclasses should not assume it will be.Gets theConstructorthat 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.- Returns:
- the
Constructorthat can be called to instantiate newLoginstances. - Throws:
LogConfigurationException- if a suitable constructor cannot be returned
-
getLowestClassLoader
private java.lang.ClassLoader getLowestClassLoader(java.lang.ClassLoader c1, java.lang.ClassLoader c2)Given two related class loaders, return the one which is a child of the other.- Parameters:
c1- is a class loader (including the null class loader)c2- is a class loader (including the null class loader)- Returns:
- c1 if it has c2 as an ancestor, c2 if it has c1 as an ancestor, and null if neither is an ancestor of the other.
-
getParentClassLoader
private java.lang.ClassLoader getParentClassLoader(java.lang.ClassLoader cl)
Fetch the parent class loader of a specified class loader.If a SecurityException occurs, null is returned.
Note that this method is non-static merely so logDiagnostic is available.
-
handleFlawedDiscovery
private void handleFlawedDiscovery(java.lang.String logAdapterClassName, java.lang.Throwable discoveryFlaw)Generates an internal diagnostic logging of the discovery failure and then throws aLogConfigurationExceptionthat wraps the passedThrowable.- Parameters:
logAdapterClassName- is the class name of the Log implementation that could not be instantiated. Cannot benull.discoveryFlaw- is the Throwable created by the class loader- Throws:
LogConfigurationException- ALWAYS
-
handleFlawedHierarchy
private void handleFlawedHierarchy(java.lang.ClassLoader badClassLoader, java.lang.Class<?> badClass) throws LogConfigurationExceptionReport a problem loading the log adapter, then either return (if the situation is considered recoverable) or throw a LogConfigurationException.There are two possible reasons why we successfully loaded the specified log adapter class then failed to cast it to a Log object:
- the specific class just doesn't implement the Log interface (user screwed up), or
- the specified class has bound to a Log class loaded by some other class loader; Log@ClassLoaderX cannot be cast to Log@ClassLoaderY.
Here we try to figure out which case has occurred so we can give the user some reasonable feedback.
- Parameters:
badClassLoader- is the class loader we loaded the problem class from, ie it is equivalent to badClass.getClassLoader().badClass- is a Class object with the desired name, but which does not implement Log correctly.- Throws:
LogConfigurationException- when the situation should not be recovered from.
-
informUponSimilarName
private void informUponSimilarName(java.lang.StringBuilder messageBuffer, java.lang.String name, java.lang.String candidate)Appends message if the given name is similar to the candidate.- Parameters:
messageBuffer-StringBufferthe message should be appended to, not nullname- the (trimmed) name to be test against the candidate, not nullcandidate- the candidate name (not null)
-
initConfiguration
private void initConfiguration()
Initializes a number of variables that control the behavior of this class and that can be tweaked by the user. This is done when the first logger is created, not in the constructor of this class, because we need to give the user a chance to call method setAttribute in order to configure this object.
-
initDiagnostics
private void initDiagnostics()
Initializes a string that uniquely identifies this instance, including which class loader the object was loaded from.This string will later be prefixed to each "internal logging" message emitted, so that users can clearly see any unexpected behavior.
Note that this method does not detect whether internal logging is enabled or not, nor where to output stuff if it is; that is all handled by the parent LogFactory class. This method just computes its own unique prefix for log messages.
-
isJdk13LumberjackAvailable
@Deprecated protected boolean 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 protected boolean isJdk14Available()
Deprecated.Never invoked by this class; subclasses should not assume it will be.Teststruewhether JDK 1.4 or later logging is available. Also checks that theThrowableclass supportsgetStackTrace(), which is required by Jdk14Logger.- Returns:
- Whether JDK 1.4 or later logging is available.
-
isLog4JAvailable
@Deprecated protected boolean 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.
-
isLogLibraryAvailable
private boolean isLogLibraryAvailable(java.lang.String name, java.lang.String className)Tests whether a particular logging library is present and available for use. Note that this does not affect the future behavior of this class.
-
logDiagnostic
protected void logDiagnostic(java.lang.String msg)
Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).- Parameters:
msg- diagnostic message- Since:
- 1.1
-
newInstance
protected Log newInstance(java.lang.String name) throws LogConfigurationException
Create and return a newLoginstance 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
public void release()
Releases 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
public void removeAttribute(java.lang.String name)
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
public void setAttribute(java.lang.String name, java.lang.Object value)Sets 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 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:
setAttributein classLogFactory- Parameters:
name- Name of the attribute to setvalue- Value of the attribute to set, ornullto remove any setting for this attribute
-
-