public class AndroidLogFactoryImpl extends AndroidLogFactory
Concrete subclass of AndroidLogFactory that implements the following algorithm to dynamically select a logging implementation class to
instantiate a wrapper for.
org.apache.commons.logging.AndroidLog to identify the requested implementation class.org.apache.commons.logging.AndroidLog system property to identify the requested implementation class.org.apache.commons.logging.impl.SimpleAndroidLog.
If the selected AndroidLog implementation class has a setLogFactory() method that accepts a AndroidLogFactory
parameter, this method will be called on each newly created instance to identify the associated factory. This makes factory configuration
attributes available to the AndroidLog instance, if it so desires.
This factory will remember previously created AndroidLog instances for the same name, and will return them on repeated requests to the
getInstance() method.
| Modifier and Type | Field and Description |
|---|---|
protected Map<String,Object> |
attributes
Configuration attributes.
|
protected Map<String,AndroidLog> |
instances
The
AndroidLog instances that have already been created, keyed by logger name. |
static String |
LOG_PROPERTY
The name (
org.apache.commons.logging.AndroidLog) of the system property identifying our AndroidLog implementation class. |
protected Constructor<?> |
logConstructor
The one-argument constructor of the
AndroidLog 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 AndroidLog method, if it exists. |
protected Class<?>[] |
logMethodSignature
The signature of the
setLogFactory method to be used. |
DIAGNOSTICS_DEST_PROPERTY, factories, FACTORY_DEFAULT, FACTORY_PROPERTIES, FACTORY_PROPERTY, PRIORITY_KEY| Constructor and Description |
|---|
AndroidLogFactoryImpl()
Public no-arguments constructor required by the lookup mechanism.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
protected static ClassLoader |
getClassLoader(Class<?> clazz)
Workaround for bug in Java1.2; in theory this method is not needed.
|
AndroidLog |
getInstance(Class<?> clazz)
Convenience method to derive a name from the specified class and call
getInstance(String) with it. |
AndroidLog |
getInstance(String name)
Construct (if necessary) and return a
AndroidLog instance, using the factory's current set of configuration attributes. |
protected static boolean |
isDiagnosticsEnabled()
Workaround for bug in Java1.2; in theory this method is not needed.
|
protected void |
logDiagnostic(String msg)
Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging).
|
protected AndroidLog |
newInstance(String name)
Create and return a new
AndroidLog instance for the specified name. |
void |
release()
Release any internal references to previously created
AndroidLog 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.
|
createFactory, getFactory, getLog, getLog, logRawDiagnostic, newFactory, objectId, release, releaseAllpublic static final String LOG_PROPERTY
org.apache.commons.logging.AndroidLog) of the system property identifying our AndroidLog implementation class.protected Map<String,AndroidLog> instances
AndroidLog instances that have already been created, keyed by logger name.protected Constructor<?> logConstructor
AndroidLog implementation class that will be used to create new
instances. This value is initialized by getLogConstructor(), and then returned repeatedly.protected Class<?>[] logConstructorSignature
protected Method logMethod
setLogFactory method of the selected AndroidLog method, if it exists.protected Class<?>[] logMethodSignature
setLogFactory method to be used.public AndroidLogFactoryImpl()
public Object getAttribute(String name)
null if there is no such attribute.getAttribute in class AndroidLogFactoryname - Name of the attribute to returnpublic String[] getAttributeNames()
getAttributeNames in class AndroidLogFactorypublic AndroidLog getInstance(Class<?> clazz) throws LogConfigurationException
getInstance(String) with it.getInstance in class AndroidLogFactoryclazz - Class for which a suitable AndroidLog name will be derivedLogConfigurationException - if a suitable AndroidLog instance cannot be returnedpublic AndroidLog getInstance(String name) throws LogConfigurationException
Construct (if necessary) and return a AndroidLog instance, using the factory's current set of configuration attributes.
NOTE - Depending upon the implementation of the AndroidLogFactory you are using, the AndroidLog
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.
getInstance in class AndroidLogFactoryname - Logical name of the AndroidLog instance to be returned (the meaning of this name is only known to the underlying
logging implementation that is being wrapped)LogConfigurationException - if a suitable AndroidLog instance cannot be returnedpublic void release()
AndroidLog 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.release in class AndroidLogFactorypublic void removeAttribute(String name)
removeAttribute in class AndroidLogFactoryname - Name of the attribute to removepublic void setAttribute(String name, Object value)
null value is equivalent to calling
removeAttribute(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
AndroidLogFactory.getFactory().setAttribute(...)This must be done before the first AndroidLog object is created; configuration changes after that point will be ignored.
This method is also called automatically if AndroidLogFactory detects a commons-logging.properties file; every entry in that file is set automatically as an attribute here.
setAttribute in class AndroidLogFactoryname - Name of the attribute to setvalue - Value of the attribute to set, or null to remove any setting for this attributeprotected static boolean isDiagnosticsEnabled()
protected static ClassLoader getClassLoader(Class<?> clazz)
protected void logDiagnostic(String msg)
msg - diagnostic messageprotected AndroidLog newInstance(String name) throws LogConfigurationException
AndroidLog instance for the specified name.name - Name of the new loggerLogConfigurationException - if a new instance cannot be createdCopyright © 2014. All rights reserved.