Top Description Fields Constructors Methods
org.apache.juli.logging

public Class LogFactory

extends Object
Class Inheritance
Annotations
@ServiceConsumer:Log
Imports
java.lang.reflect.Constructor, java.nio.file.FileSystems, java.util.ServiceLoader, java.util.logging.LogManager, aQute.bnd.annotation.spi.ServiceConsumer

This is a modified LogFactory that uses a simple ServiceLoader based discovery mechanism with a default of using JDK based logging. An implementation that uses the full Commons Logging discovery mechanism is available as part of the Tomcat extras download. Why? It is an attempt to strike a balance between simpler code (no discovery) and providing flexibility - particularly for those projects that embed Tomcat or some of Tomcat's components - is an alternative logging implementation is desired. Note that this implementation is not just a wrapper around JDK logging (like the original commons-logging impl). It adds 2 features - a simpler configuration (which is in fact a subset of log4j.properties) and a formatter that is less ugly. The removal of 'abstract' preserves binary backward compatibility. It is possible to preserve the abstract - and introduce another (hardcoded) factory - but I see no benefit. Since this class is not intended to be extended - all protected methods are removed. This can be changed - but again, there is little value in keeping dead code. Just take a quick look at the removed code ( and it's complexity). -------------- Original comment:

Factory for creating Log instances, with discovery and configuration features similar to that employed by standard Java APIs such as JAXP.

Implementation Note

- This implementation is heavily based on the SAXParserFactory and DocumentBuilderFactory implementations (corresponding to the JAXP pluggability APIs) found in Apache Xerces.

Authors
Craig R. McClanahan, Costin Manolache, Richard A. Sitze

Field Summary

Modifier and TypeField and Description
private final Constructor<? extends Log>
private static final LogFactory

Constructor Summary

AccessConstructor and Description
private
LogFactory()

Private constructor that is not available for public use.

Method Summary

Modifier and TypeMethod and Description
public static LogFactory

Returns:

The singleton LogFactory instance
getFactory
()

Construct (if necessary) and return a LogFactory instance, using the following ordered lookup procedure to determine the name of the implementation class to be loaded.

public Log

Returns:

A log instance with the requested name
getInstance
(String
Logical 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)
name
)

Construct (if necessary) and return a Log instance, using the factory's current set of configuration attributes.

public Log

Returns:

A log instance with a name of clazz.getName()
getInstance
(Class<?>
Class for which a suitable Log name will be derived
clazz
)

Convenience method to derive a name from the specified class and call getInstance(String) with it.

public static Log

Returns:

A log instance with a name of clazz.getName()
getLog
(Class<?>
Class from which a log name will be derived
clazz
)

Convenience method to return a named logger, without the application having to care about factories.

public static Log

Returns:

A log instance with the requested name
getLog
(String
Logical 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)
name
)

Convenience method to return a named logger, without the application having to care about factories.

public static void
release(ClassLoader
ClassLoader for which to release the LogFactory
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

discoveredLogConstructorback to summary
private final Constructor<? extends Log> discoveredLogConstructor
singletonback to summary
private static final LogFactory singleton

Constructor Detail

LogFactoryback to summary
private LogFactory()

Private constructor that is not available for public use.

Method Detail

getFactoryback to summary
public static LogFactory getFactory() throws LogConfigurationException

Construct (if necessary) and return a LogFactory instance, using the following ordered lookup procedure to determine the name of the implementation class to be loaded.

  • The org.apache.commons.logging.LogFactory system property.
  • The JDK 1.3 Service Discovery mechanism
  • Use the properties file commons-logging.properties file, if found in the class path of this class. The configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above.
  • Fall back to a default implementation class (org.apache.commons.logging.impl.LogFactoryImpl).

Note

- If the properties file method of identifying the LogFactory implementation class is utilized, all of the properties defined in this file will be set as configuration attributes on the corresponding LogFactory instance.

Returns:LogFactory

The singleton LogFactory instance

Exceptions
LogConfigurationException:
if the implementation class is not available or cannot be instantiated.
getInstanceback to summary
public 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
name:String

Logical 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)

Returns:Log

A log instance with the requested name

Exceptions
LogConfigurationException:
if a suitable Log instance cannot be returned
getInstanceback to summary
public Log getInstance(Class<?> clazz) throws LogConfigurationException

Convenience method to derive a name from the specified class and call getInstance(String) with it.

Parameters
clazz:Class<?>

Class for which a suitable Log name will be derived

Returns:Log

A log instance with a name of clazz.getName()

Exceptions
LogConfigurationException:
if a suitable Log instance cannot be returned
getLogback to summary
public static Log getLog(Class<?> clazz) throws LogConfigurationException

Convenience method to return a named logger, without the application having to care about factories.

Parameters
clazz:Class<?>

Class from which a log name will be derived

Returns:Log

A log instance with a name of clazz.getName()

Exceptions
LogConfigurationException:
if a suitable Log instance cannot be returned
getLogback to summary
public static Log getLog(String name) throws LogConfigurationException

Convenience method to return a named logger, without the application having to care about factories.

Parameters
name:String

Logical 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)

Returns:Log

A log instance with the requested name

Exceptions
LogConfigurationException:
if a suitable Log instance cannot be returned
releaseback to summary
public 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.

Parameters
classLoader:ClassLoader

ClassLoader for which to release the LogFactory