org.geotoolkit.util.logging
Class LoggerFactory<L>

Object
  extended by LoggerFactory<L>
Type Parameters:
L - The type of loggers used for the implementation backend. This is the type used by external frameworks like Log4J.
Direct Known Subclasses:
CommonsLoggerFactory, Log4JLoggerFactory

@ThreadSafe
public abstract class LoggerFactory<L>
extends Object

A factory for Java Logger wrapping an other logging framework. This factory is used only when wanting to log to an other framework than Java logging. The getLogger(String) method returns some subclass of Logger (typically LoggerAdapter) that forward directly all log methods to an other framework.

Since:
2.4
Version:
3.00
Author:
Martin Desruisseaux (IRD)
See Also:
Logging, LoggerAdapter
Module:
utility/geotk-utility (download)    View source code for this class

Field Summary
static String COMMONS_LOGGING
          Deprecated. Deprecated together with Logging.setLoggerFactory(String).
static String LOG4J
          Deprecated. Deprecated together with Logging.setLoggerFactory(String).
 
Constructor Summary
protected LoggerFactory(Class<L> loggerClass)
          Creates a new factory.
 
Method Summary
protected abstract  L getImplementation(String name)
          Returns the implementation to use for the logger of the specified name.
 Class<L> getImplementationClass()
          Returns the base class of objects to be returned by getImplementation(java.lang.String).
 Logger getLogger(String name)
          Returns the logger of the specified name, or null.
protected abstract  L unwrap(Logger logger)
          Returns the implementation wrapped by the specified logger, or null if none.
protected abstract  Logger wrap(String name, L implementation)
          Wraps the specified implementation in a Java logger.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMONS_LOGGING

@Deprecated
public static final String COMMONS_LOGGING
Deprecated. Deprecated together with Logging.setLoggerFactory(String).
The Apache's Commons-logging framework. This value can be given to Logging.setLoggerFactory(String) in order to force explicitly usage of this logging framework. Note that this is usually not needed, since this framework is selected automatically if geotk-logging-commons.jar is found on the classpath.

Since:
3.00
See Also:
Logging.setLoggerFactory(String), Constant Field Values

LOG4J

@Deprecated
public static final String LOG4J
Deprecated. Deprecated together with Logging.setLoggerFactory(String).
The Log4J framework. This value can be given to Logging.setLoggerFactory(String) in order to force explicitly usage of this logging framework. Note that this is usually not needed, since this framework is selected automatically if geotk-logging-log4j.jar is found on the classpath.

Since:
3.00
See Also:
Logging.setLoggerFactory(String), Constant Field Values
Constructor Detail

LoggerFactory

protected LoggerFactory(Class<L> loggerClass)
Creates a new factory.

Parameters:
loggerClass - The class of the wrapped logger.
Method Detail

getLogger

public Logger getLogger(String name)
Returns the logger of the specified name, or null. If this method has already been invoked previously with the same name argument, then it may returns the same logger provided that:

Otherwise this method returns a new Logger instance, or null if the standard Java logging framework should be used.

Parameters:
name - The name of the logger.
Returns:
The logger, or null.

getImplementationClass

public Class<L> getImplementationClass()
Returns the base class of objects to be returned by getImplementation(java.lang.String). The class depends on the underlying logging framework (Log4J, SLF4J, etc.).

Returns:
The type of loggers used for the implementation backend.

getImplementation

protected abstract L getImplementation(String name)
Returns the implementation to use for the logger of the specified name. The object to be returned depends on the logging framework (Log4J, SLF4J, etc.). If the target framework redirects logging events to Java logging, then this method should returns null since we should not use wrapper at all.

Parameters:
name - The name of the logger.
Returns:
The logger as an object of the target logging framework (Log4J, SLF4J, etc.), or null if the target framework would redirect to the Java logging framework.

wrap

protected abstract Logger wrap(String name,
                               L implementation)
Wraps the specified implementation in a Java logger.

Parameters:
name - The name of the logger.
implementation - An implementation returned by getImplementation(java.lang.String).
Returns:
A new logger wrapping the specified implementation.

unwrap

protected abstract L unwrap(Logger logger)
Returns the implementation wrapped by the specified logger, or null if none. If the specified logger is not an instance of the expected class, then this method should returns null.

Parameters:
logger - The logger to test.
Returns:
The implementation wrapped by the specified logger, or null if none.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.