org.geotools.util.logging
Class LoggerAdapter

java.lang.Object
  extended by java.util.logging.Logger
      extended by org.geotools.util.logging.LoggerAdapter

public abstract class LoggerAdapter
extends java.util.logging.Logger

An adapter that redirect all Java logging events to an other logging framework. This class redefines the severe, warning, info, config, fine, finer and finest methods as abstract ones. Subclasses should implement those methods in order to map Java logging levels to the backend logging framework.

All log methods are overriden in order to redirect to one of the above-cited methods. Note that this is the opposite approach than the Java logging framework one, which implemented everything on top of Logger.log(LogRecord). This adapter is defined in terms of severefinest methods instead because external frameworks like Commons-logging don't work with LogRecord, and sometime provides nothing else than convenience methods equivalent to severefinest.

Restrictions
Because the configuration is expected to be fully controled by the external logging framework, every configuration methods inherited from Logger are disabled:

Since LoggerAdapters do not hold any configuration by themself, it is not strictly necessary to add them to the log manager. The adapters can be created, garbage-collected and recreated again while preserving their behavior since their configuration is entirely contained in the external logging framework.

Localization
This logger is always created without resource bundles. Localizations must be performed through explicit calls to logrb or log(LogRecord) methods. This is suffisient for GeoTools needs, which performs all localizations through the later. Note that those methods will be slower in this LoggerAdapter than the default Logger because this adapter localizes and formats records immediately instead of letting the Handler performs this work only if needed.

Logging levels
If a log record level is not one of the predefined ones, then this class maps to the first level below the specified one. For example if a log record has some level between FINE and FINER, then the finer method will be invoked. See isLoggable(java.util.logging.Level) for implementation tips taking advantage of this rule.

Since:
2.4
Version:
$Id: LoggerAdapter.java 30640 2008-06-12 17:34:32Z acuster $
Author:
Martin Desruisseaux
See Also:
Logging

Field Summary
 
Fields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME
 
Constructor Summary
protected LoggerAdapter(java.lang.String name)
          Creates a new logger.
 
Method Summary
 void addHandler(java.util.logging.Handler handler)
          Do nothing since this logger adapter does not supports handlers.
abstract  void config(java.lang.String message)
          Logs an CONFIG message.
 void entering(java.lang.String sourceClass, java.lang.String sourceMethod)
          Logs a method entry to the debug level.
 void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object param)
          Logs a method entry to the debug level with one parameter.
 void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object[] params)
          Logs a method entry to the debug level with many parameters.
 void exiting(java.lang.String sourceClass, java.lang.String sourceMethod)
          Logs a method return to the debug level.
 void exiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)
          Logs a method return to the debug level.
abstract  void fine(java.lang.String message)
          Logs a FINE message.
abstract  void finer(java.lang.String message)
          Logs a FINER message.
abstract  void finest(java.lang.String message)
          Logs a FINEST message.
protected  java.util.logging.Level getDebugLevel()
          Returns the level for entering(java.lang.String, java.lang.String), exiting(java.lang.String, java.lang.String) and throwing(java.lang.String, java.lang.String, java.lang.Throwable) methods.
abstract  java.util.logging.Level getLevel()
          Returns the level for this logger.
abstract  void info(java.lang.String message)
          Logs an INFO message.
abstract  boolean isLoggable(java.util.logging.Level level)
          Returns true if the specified level is loggable.
 void log(java.util.logging.Level level, java.lang.String message)
          Logs a record at the specified level.
 void log(java.util.logging.Level level, java.lang.String message, java.lang.Object param)
          Logs a record at the specified level.
 void log(java.util.logging.Level level, java.lang.String message, java.lang.Object[] params)
          Logs a record at the specified level.
 void log(java.util.logging.Level level, java.lang.String message, java.lang.Throwable thrown)
          Logs a record at the specified level.
 void log(java.util.logging.LogRecord record)
          Logs a record.
 void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message)
          Logs a record at the specified level.
 void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Object param)
          Logs a record at the specified level.
 void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Object[] params)
          Logs a record at the specified level.
 void logp(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String message, java.lang.Throwable thrown)
          Logs a record at the specified level.
 void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message)
          Logs a localizable record at the specified level.
 void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Object param)
          Logs a localizable record at the specified level.
 void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Object[] params)
          Logs a localizable record at the specified level.
 void logrb(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String bundleName, java.lang.String message, java.lang.Throwable thrown)
          Logs a localizable record at the specified level.
 void removeHandler(java.util.logging.Handler handler)
          Do nothing since this logger adapter does not support handlers.
 void setFilter(java.util.logging.Filter filter)
          Do nothing since this logger adapter does not support filters.
abstract  void setLevel(java.util.logging.Level level)
          Sets the level for this logger.
 void setParent(java.util.logging.Logger parent)
          Do nothing since this logger adapter does not support arbitrary parents.
 void setUseParentHandlers(boolean useParentHandlers)
          Do nothing since this logger never use parent handlers.
abstract  void severe(java.lang.String message)
          Logs a SEVERE message.
 void throwing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable thrown)
          Logs a method failure to the debug level.
abstract  void warning(java.lang.String message)
          Logs a WARNING message.
 
Methods inherited from class java.util.logging.Logger
getAnonymousLogger, getAnonymousLogger, getFilter, getHandlers, getLogger, getLogger, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggerAdapter

protected LoggerAdapter(java.lang.String name)
Creates a new logger.

Parameters:
name - The logger name.
Method Detail

setLevel

public abstract void setLevel(java.util.logging.Level level)
Sets the level for this logger. Subclasses must redirect the call to the external logging framework, or do nothing if the level can not be changed programmatically.

Overrides:
setLevel in class java.util.logging.Logger

getLevel

public abstract java.util.logging.Level getLevel()
Returns the level for this logger. Subclasses shall get this level from the external logging framework.

Overrides:
getLevel in class java.util.logging.Logger

getDebugLevel

protected java.util.logging.Level getDebugLevel()
Returns the level for entering(java.lang.String, java.lang.String), exiting(java.lang.String, java.lang.String) and throwing(java.lang.String, java.lang.String, java.lang.Throwable) methods. The default implementation returns Level.FINER, which is consistent with the value used in the Java logging framework. Subclasses should override this method if a different debug level is wanted.


isLoggable

public abstract boolean isLoggable(java.util.logging.Level level)
Returns true if the specified level is loggable.

Implementation tip
Given that Level.intValue() for all predefined levels are documented in the Level specification and are multiple of 100, given that integer divisions are rounded toward zero and given rule documented in this class javadoc, then logging levels can be efficiently mapped to predefined levels using switch statements as below. This statement has good chances to be compiled to the tableswitch bytecode rather than lookupswitch (see Compiling Switches in The Java Virtual Machine Specification).

Overrides:
isLoggable in class java.util.logging.Logger

severe

public abstract void severe(java.lang.String message)
Logs a SEVERE message.

Overrides:
severe in class java.util.logging.Logger

warning

public abstract void warning(java.lang.String message)
Logs a WARNING message.

Overrides:
warning in class java.util.logging.Logger

info

public abstract void info(java.lang.String message)
Logs an INFO message.

Overrides:
info in class java.util.logging.Logger

config

public abstract void config(java.lang.String message)
Logs an CONFIG message.

Overrides:
config in class java.util.logging.Logger

fine

public abstract void fine(java.lang.String message)
Logs a FINE message.

Overrides:
fine in class java.util.logging.Logger

finer

public abstract void finer(java.lang.String message)
Logs a FINER message.

Overrides:
finer in class java.util.logging.Logger

finest

public abstract void finest(java.lang.String message)
Logs a FINEST message.

Overrides:
finest in class java.util.logging.Logger

entering

public void entering(java.lang.String sourceClass,
                     java.lang.String sourceMethod)
Logs a method entry to the debug level. Compared to the default Logger, this implementation bypass the level check in order to let the backing logging framework do its own check.

Overrides:
entering in class java.util.logging.Logger

entering

public void entering(java.lang.String sourceClass,
                     java.lang.String sourceMethod,
                     java.lang.Object param)
Logs a method entry to the debug level with one parameter. Compared to the default Logger, this implementation bypass the level check in order to let the backing logging framework do its own check.

Overrides:
entering in class java.util.logging.Logger

entering

public void entering(java.lang.String sourceClass,
                     java.lang.String sourceMethod,
                     java.lang.Object[] params)
Logs a method entry to the debug level with many parameters. Compared to the default Logger, this implementation bypass the level check in order to let the backing logging framework do its own check.

Overrides:
entering in class java.util.logging.Logger

exiting

public void exiting(java.lang.String sourceClass,
                    java.lang.String sourceMethod)
Logs a method return to the debug level. Compared to the default Logger, this implementation bypass the level check in order to let the backing logging framework do its own check.

Overrides:
exiting in class java.util.logging.Logger

exiting

public void exiting(java.lang.String sourceClass,
                    java.lang.String sourceMethod,
                    java.lang.Object result)
Logs a method return to the debug level. Compared to the default Logger, this implementation bypass the level check in order to let the backing logging framework do its own check.

Overrides:
exiting in class java.util.logging.Logger

throwing

public void throwing(java.lang.String sourceClass,
                     java.lang.String sourceMethod,
                     java.lang.Throwable thrown)
Logs a method failure to the debug level. Compared to the default Logger, this implementation bypass the level check in order to let the backing logging framework do its own check.

Overrides:
throwing in class java.util.logging.Logger

log

public void log(java.util.logging.LogRecord record)
Logs a record. The default implementation delegates to logrb.

Overrides:
log in class java.util.logging.Logger

log

public void log(java.util.logging.Level level,
                java.lang.String message)
Logs a record at the specified level. The default implementation delegates to one of the severe, warning, info, config, fine, finer or finest methods according the supplied level.

Overrides:
log in class java.util.logging.Logger

log

public void log(java.util.logging.Level level,
                java.lang.String message,
                java.lang.Throwable thrown)
Logs a record at the specified level. The default implementation discards the exception and delegates to log(level, message).

Overrides:
log in class java.util.logging.Logger

log

public void log(java.util.logging.Level level,
                java.lang.String message,
                java.lang.Object param)
Logs a record at the specified level. The defaut implementation delegates to log(level, message, params) where the params array is built from the param object.

Overrides:
log in class java.util.logging.Logger

log

public void log(java.util.logging.Level level,
                java.lang.String message,
                java.lang.Object[] params)
Logs a record at the specified level. The defaut implementation formats the message immediately, then delegates to log(level, message).

Overrides:
log in class java.util.logging.Logger

logp

public void logp(java.util.logging.Level level,
                 java.lang.String sourceClass,
                 java.lang.String sourceMethod,
                 java.lang.String message)
Logs a record at the specified level. The defaut implementation discards the source class and source method, then delegates to log(level, message).

Overrides:
logp in class java.util.logging.Logger

logp

public void logp(java.util.logging.Level level,
                 java.lang.String sourceClass,
                 java.lang.String sourceMethod,
                 java.lang.String message,
                 java.lang.Throwable thrown)
Logs a record at the specified level. The defaut implementation discards the source class and source method, then delegates to log(level, message, thrown).

Overrides:
logp in class java.util.logging.Logger

logp

public void logp(java.util.logging.Level level,
                 java.lang.String sourceClass,
                 java.lang.String sourceMethod,
                 java.lang.String message,
                 java.lang.Object param)
Logs a record at the specified level. The defaut implementation delegates to logp(level, sourceClass, sourceMethod, message, params) where the params array is built from the param object.

Note that sourceClass and sourceMethod will be discarted unless the target logp method has been overriden.

Overrides:
logp in class java.util.logging.Logger

logp

public void logp(java.util.logging.Level level,
                 java.lang.String sourceClass,
                 java.lang.String sourceMethod,
                 java.lang.String message,
                 java.lang.Object[] params)
Logs a record at the specified level. The defaut implementation formats the message immediately, then delegates to logp(level, sourceClass, sourceMethod, message).

Note that sourceClass and sourceMethod will be discarted unless the target logp method has been overriden.

Overrides:
logp in class java.util.logging.Logger

logrb

public void logrb(java.util.logging.Level level,
                  java.lang.String sourceClass,
                  java.lang.String sourceMethod,
                  java.lang.String bundleName,
                  java.lang.String message)
Logs a localizable record at the specified level. The defaut implementation localizes the message immediately, then delegates to logp(level, sourceClass, sourceMethod, message).

Overrides:
logrb in class java.util.logging.Logger

logrb

public void logrb(java.util.logging.Level level,
                  java.lang.String sourceClass,
                  java.lang.String sourceMethod,
                  java.lang.String bundleName,
                  java.lang.String message,
                  java.lang.Throwable thrown)
Logs a localizable record at the specified level. The defaut implementation localizes the message immediately, then delegates to logp(level, sourceClass, sourceMethod, message, thrown).

Overrides:
logrb in class java.util.logging.Logger

logrb

public void logrb(java.util.logging.Level level,
                  java.lang.String sourceClass,
                  java.lang.String sourceMethod,
                  java.lang.String bundleName,
                  java.lang.String message,
                  java.lang.Object param)
Logs a localizable record at the specified level. The defaut implementation localizes the message immediately, then delegates to logp(level, sourceClass, sourceMethod, message, param).

Overrides:
logrb in class java.util.logging.Logger

logrb

public void logrb(java.util.logging.Level level,
                  java.lang.String sourceClass,
                  java.lang.String sourceMethod,
                  java.lang.String bundleName,
                  java.lang.String message,
                  java.lang.Object[] params)
Logs a localizable record at the specified level. The defaut implementation localizes the message immediately, then delegates to logp(level, sourceClass, sourceMethod, message, params).

Overrides:
logrb in class java.util.logging.Logger

addHandler

public void addHandler(java.util.logging.Handler handler)
Do nothing since this logger adapter does not supports handlers. The configuration should be fully controlled by the external logging framework (e.g. Commons-logging) instead, which is not expected to use Handler objects.

Overrides:
addHandler in class java.util.logging.Logger

removeHandler

public void removeHandler(java.util.logging.Handler handler)
Do nothing since this logger adapter does not support handlers.

Overrides:
removeHandler in class java.util.logging.Logger

setUseParentHandlers

public void setUseParentHandlers(boolean useParentHandlers)
Do nothing since this logger never use parent handlers. This is consistent with addHandler(java.util.logging.Handler) not allowing to add any handlers, and avoid mixing loggings from the external framework with Java loggings.

Overrides:
setUseParentHandlers in class java.util.logging.Logger

setParent

public void setParent(java.util.logging.Logger parent)
Do nothing since this logger adapter does not support arbitrary parents. More specifically, it should not inherits any configuration from a parent logger using the Java logging framework.

Overrides:
setParent in class java.util.logging.Logger

setFilter

public void setFilter(java.util.logging.Filter filter)
Do nothing since this logger adapter does not support filters. It is difficult to query efficiently the filter in this LoggerAdapter architecture (e.g. we would need to make sure that Filter.isLoggable(java.util.logging.LogRecord) is invoked only once even if a log call is cascaded into many other log calls, and this test must works in multi-threads environment).

Overrides:
setFilter in class java.util.logging.Logger


Copyright © 1996-2010 Geotools. All Rights Reserved.