Class LogFactory
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).
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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic LogFactoryReturn the singletonLogFactoryinstance.getInstance(Class<?> clazz) Convenience method to derive a name from the specified class and callgetInstance(String)with it.getInstance(String name) Construct (if necessary) and return aLoginstance, using the factory's current set of configuration attributes.static LogConvenience method to return a named logger, without the application having to care about factories.static LogConvenience method to return a named logger, without the application having to care about factories.static voidrelease(ClassLoader classLoader) Reset theLogManager, unless the standardjava.util.logging.LogManagerimplementation is in use.
-
Method Details
-
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.- 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 log instance with the requested name
- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
getInstance
Convenience method to derive a name from the specified class and callgetInstance(String)with it.- Parameters:
clazz- Class for which a suitable Log name will be derived- Returns:
- A log instance with a name of clazz.getName()
- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
getFactory
Return the singleton
LogFactoryinstance. TheLogimplementation is discovered once, using aServiceLoaderlookup for providers of theLoginterface, falling back toDirectJDKLogif no suitable provider is found.- Returns:
- The singleton LogFactory instance
- Throws:
LogConfigurationException- if the implementation class is not available or cannot be instantiated.
-
getLog
Convenience method to return a named logger, without the application having to care about factories.- Parameters:
clazz- Class from which a log name will be derived- Returns:
- A log instance with a name of clazz.getName()
- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
getLog
Convenience method to return a named logger, without the application having to care about factories.- 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 log instance with the requested name
- Throws:
LogConfigurationException- if a suitableLoginstance cannot be returned
-
release
Reset theLogManager, unless the standardjava.util.logging.LogManagerimplementation is in use. The given class loader is not used: the JULI log manager associates its configuration with the current thread's context class loader.- Parameters:
classLoader- ClassLoader for which to release the LogFactory. Not used by this implementation.
-