• BlackBerry Dynamics
  • Runtime library for Android applications
  • 10.1.0.35
LogFactoryImpl Class Reference

Inherits LogFactory.

Description

Concrete subclass of com.good.gd.apache.commons.logging.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 com.good.gd.apache.commons.logging.Log implementation class has a setLogFactory() method that accepts a com.good.gd.apache.commons.logging.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.

Author
Rod Waldhoff
Craig R. McClanahan
Richard A. Sitze
Brian Stansberry
Version
Revision
399224
Date
2006-05-03 10:25:54 +0100 (Wed, 03 May 2006)

Notice


The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

 LogFactoryImpl ()
 Public no-arguments constructor required by the lookup mechanism.
 
Object getAttribute (String name)
 Return the configuration attribute with the specified name (if any), or null if there is no such attribute. More...
 
String[] getAttributeNames ()
 Return an array containing the names of all currently defined configuration attributes. More...
 
Log getInstance (Class clazz) throws LogConfigurationException
 Convenience method to derive a name from the specified class and call getInstance(String) with it. More...
 
Log getInstance (String name) throws LogConfigurationException
 
void release ()
 Release any internal references to previously created com.good.gd.apache.commons.logging.Log instances returned by this factory. More...
 
void removeAttribute (String name)
 Remove any configuration attribute associated with the specified name. More...
 
void setAttribute (String name, Object value)
 Set the configuration attribute with the specified name. More...
 

Static Public Attributes

static final String LOG_PROPERTY
 The name (org.apache.commons.logging.Log) of the system property identifying our com.good.gd.apache.commons.logging.Log implementation class.
 
static final 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 behaviour when a bad context-classloader is encountered. More...
 
static final 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 behaviour when a bad logging adapter class is encountered during logging discovery. More...
 
static final 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 behaviour when a logging adapter class is encountered which has bound to the wrong Log class implementation. More...
 
- Static Public Attributes inherited from LogFactory
static final String PRIORITY_KEY = "priority"
 The name (priority) of the key in the config file used to specify the priority of that particular config file. More...
 
static final String TCCL_KEY = "use_tccl"
 The name (use_tccl) of the key in the config file used to specify whether logging classes should be loaded via the thread context class loader (TCCL), or not. More...
 
static final String FACTORY_PROPERTY
 The name (org.apache.commons.logging.LogFactory) of the property used to identify the LogFactory implementation class name. More...
 
static final String FACTORY_DEFAULT
 The fully qualified class name of the fallback LogFactory implementation class to use, if no other can be found.
 
static final String FACTORY_PROPERTIES
 The name (commons-logging.properties) of the properties file to search for.
 
static final String DIAGNOSTICS_DEST_PROPERTY
 The name (org.apache.commons.logging.diagnostics.dest) of the property used to enable internal commons-logging diagnostic output, in order to get information on what logging implementations are being discovered, what classloaders they are loaded through, etc. More...
 
static final String HASHTABLE_IMPLEMENTATION_PROPERTY
 

Protected Member Functions

void logDiagnostic (String msg)
 Output a diagnostic message to a user-specified destination (if the user has enabled diagnostic logging). More...
 
String getLogClassName ()
 Return the fully qualified Java classname of the com.good.gd.apache.commons.logging.Log implementation we will be using. More...
 
Constructor getLogConstructor () throws LogConfigurationException
 
boolean isJdk13LumberjackAvailable ()
 Is JDK 1.3 with Lumberjack logging available? More...
 
boolean isJdk14Available ()
 
boolean isLog4JAvailable ()
 Is a Log4J implementation available? More...
 
Log newInstance (String name) throws LogConfigurationException
 Create and return a new com.good.gd.apache.commons.logging.Log instance for the specified name. More...
 
- Protected Member Functions inherited from LogFactory
 LogFactory ()
 Protected constructor that is not available for public use.
 

Static Protected Member Functions

static ClassLoader getContextClassLoader () throws LogConfigurationException
 Gets the context classloader. More...
 
static boolean isDiagnosticsEnabled ()
 Workaround for bug in Java1.2; in theory this method is not needed. More...
 
static ClassLoader getClassLoader (Class clazz)
 Workaround for bug in Java1.2; in theory this method is not needed. More...
 
- Static Protected Member Functions inherited from LogFactory
static ClassLoader directGetContextClassLoader () throws LogConfigurationException
 Return the thread context class loader if available; otherwise return null. More...
 
static LogFactory newFactory (final String factoryClass, final ClassLoader classLoader, final ClassLoader contextClassLoader) throws LogConfigurationException
 Return a new instance of the specified LogFactory implementation class, loaded by the specified class loader. More...
 
static LogFactory newFactory (final String factoryClass, final ClassLoader classLoader)
 Method provided for backwards compatibility; see newFactory version that takes 3 parameters. More...
 
static Object createFactory (String factoryClass, ClassLoader classLoader)
 Implements the operations described in the javadoc for newFactory. More...
 
static final void logRawDiagnostic (String msg)
 Write the specified message to the internal logging destination. More...
 

Protected Attributes

Hashtable attributes = new Hashtable()
 Configuration attributes.
 
Hashtable instances = new Hashtable()
 The com.good.gd.apache.commons.logging.Log instances that have already been created, keyed by logger name.
 
Constructor logConstructor = null
 The one-argument constructor of the com.good.gd.apache.commons.logging.Log implementation class that will be used to create new instances. More...
 
Class logConstructorSignature []
 The signature of the Constructor to be used.
 
Method logMethod = null
 The one-argument setLogFactory method of the selected com.good.gd.apache.commons.logging.Log method, if it exists.
 
Class logMethodSignature []
 The signature of the setLogFactory method to be used.
 

Static Protected Attributes

static final String LOG_PROPERTY_OLD
 The deprecated system property used for backwards compatibility with old versions of JCL.
 
- Static Protected Attributes inherited from LogFactory
static final String SERVICE_ID
 JDK1.3+ 'Service Provider' specification.
 
static Hashtable factories = null
 The previously constructed LogFactory instances, keyed by the ClassLoader with which it was created.
 
static LogFactory nullClassLoaderFactory = null
 Prevously constructed LogFactory instance as in the factories map, but for the case where getClassLoader returns null. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from LogFactory
static LogFactory getFactory () throws LogConfigurationException
 
static Log getLog (Class clazz) throws LogConfigurationException
 Convenience method to return a named logger, without the application having to care about factories. More...
 
static Log getLog (String name) throws LogConfigurationException
 Convenience method to return a named logger, without the application having to care about factories. More...
 
static void release (ClassLoader classLoader)
 Release any internal references to previously created LogFactory instances that have been associated with the specified class loader (if any), after calling the instance method release() on each of them. More...
 
static void releaseAll ()
 Release any internal references to previously created LogFactory instances, after calling the instance method release() on each of them. More...
 
static String objectId (Object o)
 Returns a string that uniquely identifies the specified object, including its class. More...
 

Member Function Documentation

◆ getAttribute()

Object getAttribute ( String  name)
Parameters
nameName of the attribute to return

Reimplemented from LogFactory.

◆ getAttributeNames()

String [] getAttributeNames ( )

If there are no such attributes, a zero length array is returned.

Reimplemented from LogFactory.

◆ getInstance() [1/2]

Log getInstance ( Class  clazz) throws LogConfigurationException
Parameters
clazzClass for which a suitable Log name will be derived
Exceptions
LogConfigurationExceptionif a suitable Log instance cannot be returned

Reimplemented from LogFactory.

◆ getInstance() [2/2]

Log getInstance ( String  name) throws LogConfigurationException

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
nameLogical 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)
Exceptions
LogConfigurationExceptionif a suitable Log instance cannot be returned

Reimplemented from LogFactory.

◆ release()

void release ( )

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.

Reimplemented from LogFactory.

◆ removeAttribute()

void removeAttribute ( String  name)

If there is no such attribute, no action is taken.

Parameters
nameName of the attribute to remove

Reimplemented from LogFactory.

◆ setAttribute()

void setAttribute ( String  name,
Object  value 
)

Calling this with a 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

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.

Parameters
nameName of the attribute to set
valueValue of the attribute to set, or null to remove any setting for this attribute

Reimplemented from LogFactory.

◆ getContextClassLoader()

static ClassLoader getContextClassLoader ( ) throws LogConfigurationException
staticprotected

This method is a workaround for a java 1.2 compiler bug.

Since
1.1

Reimplemented from LogFactory.

◆ isDiagnosticsEnabled()

static boolean isDiagnosticsEnabled ( )
staticprotected

See LogFactory.isDiagnosticsEnabled.

Reimplemented from LogFactory.

◆ getClassLoader()

static ClassLoader getClassLoader ( Class  clazz)
staticprotected

See LogFactory.getClassLoader.

Since
1.1

Reimplemented from LogFactory.

◆ logDiagnostic()

void logDiagnostic ( String  msg)
protected
Parameters
msgdiagnostic message
Since
1.1

Reimplemented from LogFactory.

◆ getLogClassName()

String getLogClassName ( )
protected
Deprecated:
Never invoked by this class; subclasses should not assume it will be.

◆ getLogConstructor()

Constructor getLogConstructor ( ) throws LogConfigurationException
protected

Return the Constructor that can be called to instantiate new com.good.gd.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.

Exceptions
LogConfigurationExceptionif a suitable constructor cannot be returned
Deprecated:
Never invoked by this class; subclasses should not assume it will be.

◆ isJdk13LumberjackAvailable()

boolean isJdk13LumberjackAvailable ( )
protected
Deprecated:
Never invoked by this class; subclasses should not assume it will be.

◆ isJdk14Available()

boolean isJdk14Available ( )
protected

Return true if JDK 1.4 or later logging is available. Also checks that the Throwable class supports getStackTrace(), which is required by Jdk14Logger.

Deprecated:
Never invoked by this class; subclasses should not assume it will be.

◆ isLog4JAvailable()

boolean isLog4JAvailable ( )
protected
Deprecated:
Never invoked by this class; subclasses should not assume it will be.

◆ newInstance()

Log newInstance ( String  name) throws LogConfigurationException
protected
Parameters
nameName of the new logger
Exceptions
LogConfigurationExceptionif a new instance cannot be created

Member Data Documentation

◆ ALLOW_FLAWED_CONTEXT_PROPERTY

final String ALLOW_FLAWED_CONTEXT_PROPERTY
static
Initial value:
=
"org.apache.commons.logging.Log.allowFlawedContext"

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.

◆ ALLOW_FLAWED_DISCOVERY_PROPERTY

final String ALLOW_FLAWED_DISCOVERY_PROPERTY
static
Initial value:
=
"org.apache.commons.logging.Log.allowFlawedDiscovery"

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.

◆ ALLOW_FLAWED_HIERARCHY_PROPERTY

final String ALLOW_FLAWED_HIERARCHY_PROPERTY
static
Initial value:
=
"org.apache.commons.logging.Log.allowFlawedHierarchy"

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.

◆ logConstructor

Constructor logConstructor = null
protected

This value is initialized by getLogConstructor(), and then returned repeatedly.