|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectLogger
LoggerAdapter
public abstract class LoggerAdapter
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 severe
… finest
methods instead because external frameworks like
Commons-logging
don't work with LogRecord
, and sometime provides nothing else than convenience methods
equivalent to severe
… finest
.
Restrictions
Because the configuration is expected to be fully controled by the external logging
framework, every configuration methods inherited from Logger
are disabled:
addHandler(java.util.logging.Handler)
since the handling is performed by the external framework.setUseParentHandlers(boolean)
since this adapter never delegates to the parent handlers. This is consistent with the
previous item and avoid mixing loggings from the external framework with Java loggings.setParent(java.util.logging.Logger)
since this adapter should not inherits any configuration from a parent logger using the
Java logging framework.setFilter(java.util.logging.Filter)
for keeping this LoggerAdapter
simple.
Since LoggerAdapter
s 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.
Logging
Field Summary |
---|
Fields inherited from class Logger |
---|
global |
Constructor Summary | |
---|---|
protected |
LoggerAdapter(String name)
Creates a new logger. |
Method Summary | |
---|---|
void |
addHandler(Handler handler)
Do nothing since this logger adapter does not supports handlers. |
abstract void |
config(String message)
Logs an CONFIG message. |
void |
entering(String sourceClass,
String sourceMethod)
Logs a method entry to the debug level. |
void |
entering(String sourceClass,
String sourceMethod,
Object param)
Logs a method entry to the debug level with one parameter. |
void |
entering(String sourceClass,
String sourceMethod,
Object[] params)
Logs a method entry to the debug level with many parameters. |
void |
exiting(String sourceClass,
String sourceMethod)
Logs a method return to the debug level. |
void |
exiting(String sourceClass,
String sourceMethod,
Object result)
Logs a method return to the debug level. |
abstract void |
fine(String message)
Logs a FINE message. |
abstract void |
finer(String message)
Logs a FINER message. |
abstract void |
finest(String message)
Logs a FINEST message. |
protected 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 Level |
getLevel()
Returns the level for this logger. |
abstract void |
info(String message)
Logs an INFO message. |
abstract boolean |
isLoggable(Level level)
Returns true if the specified level is loggable. |
void |
log(Level level,
String message)
Logs a record at the specified level. |
void |
log(Level level,
String message,
Object param)
Logs a record at the specified level. |
void |
log(Level level,
String message,
Object[] params)
Logs a record at the specified level. |
void |
log(Level level,
String message,
Throwable thrown)
Logs a record at the specified level. |
void |
log(LogRecord record)
Logs a record. |
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message)
Logs a record at the specified level. |
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message,
Object param)
Logs a record at the specified level. |
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message,
Object[] params)
Logs a record at the specified level. |
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message,
Throwable thrown)
Logs a record at the specified level. |
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message)
Logs a localizable record at the specified level. |
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message,
Object param)
Logs a localizable record at the specified level. |
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message,
Object[] params)
Logs a localizable record at the specified level. |
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message,
Throwable thrown)
Logs a localizable record at the specified level. |
void |
removeHandler(Handler handler)
Do nothing since this logger adapter does not support handlers. |
void |
setFilter(Filter filter)
Do nothing since this logger adapter does not support filters. |
abstract void |
setLevel(Level level)
Sets the level for this logger. |
void |
setParent(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(String message)
Logs a SEVERE message. |
void |
throwing(String sourceClass,
String sourceMethod,
Throwable thrown)
Logs a method failure to the debug level. |
abstract void |
warning(String message)
Logs a WARNING message. |
Methods inherited from class Logger |
---|
getAnonymousLogger, getAnonymousLogger, getFilter, getHandlers, getLogger, getLogger, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected LoggerAdapter(String name)
name
- The logger name.Method Detail |
---|
public abstract void setLevel(Level level)
setLevel
in class Logger
public abstract Level getLevel()
getLevel
in class Logger
protected Level getDebugLevel()
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.
public abstract boolean isLoggable(Level level)
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 classLogger
public abstract void severe(String message)
SEVERE
message.
severe
in class Logger
public abstract void warning(String message)
WARNING
message.
warning
in class Logger
public abstract void info(String message)
INFO
message.
info
in class Logger
public abstract void config(String message)
CONFIG
message.
config
in class Logger
public abstract void fine(String message)
FINE
message.
fine
in class Logger
public abstract void finer(String message)
FINER
message.
finer
in class Logger
public abstract void finest(String message)
FINEST
message.
finest
in class Logger
public void entering(String sourceClass, String sourceMethod)
Logger
, this implementation bypass the level check in order to let
the backing logging framework do its own check.
entering
in class Logger
public void entering(String sourceClass, String sourceMethod, Object param)
Logger
, this implementation bypass the level check in
order to let the backing logging framework do its own check.
entering
in class Logger
public void entering(String sourceClass, String sourceMethod, Object[] params)
Logger
, this implementation bypass the level check in
order to let the backing logging framework do its own check.
entering
in class Logger
public void exiting(String sourceClass, String sourceMethod)
Logger
, this implementation bypass the level check in order to let
the backing logging framework do its own check.
exiting
in class Logger
public void exiting(String sourceClass, String sourceMethod, Object result)
Logger
, this implementation bypass the level check in order to let
the backing logging framework do its own check.
exiting
in class Logger
public void throwing(String sourceClass, String sourceMethod, Throwable thrown)
Logger
, this implementation bypass the level check in order to let
the backing logging framework do its own check.
throwing
in class Logger
public void log(LogRecord record)
logrb
.
log
in class Logger
public void log(Level level, String message)
severe
, warning
, info
,
config
, fine
, finer
or
finest
methods according the supplied level.
log
in class Logger
public void log(Level level, String message, Throwable thrown)
log(level, message)
.
log
in class Logger
public void log(Level level, String message, Object param)
log(level, message, params)
where the params
array is built from the param
object.
log
in class Logger
public void log(Level level, String message, Object[] params)
log(level, message)
.
log
in class Logger
public void logp(Level level, String sourceClass, String sourceMethod, String message)
log(level, message)
.
logp
in class Logger
public void logp(Level level, String sourceClass, String sourceMethod, String message, Throwable thrown)
log(level, message, thrown)
.
logp
in class Logger
public void logp(Level level, String sourceClass, String sourceMethod, String message, Object param)
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.
logp
in class Logger
public void logp(Level level, String sourceClass, String sourceMethod, String message, Object[] params)
logp(level, sourceClass, sourceMethod, message)
.
Note that sourceClass
and sourceMethod
will be discarted unless the
target logp
method has been overriden.
logp
in class Logger
public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String message)
logp(level, sourceClass, sourceMethod, message)
.
logrb
in class Logger
public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String message, Throwable thrown)
logp(level, sourceClass, sourceMethod, message, thrown)
.
logrb
in class Logger
public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String message, Object param)
logp(level, sourceClass, sourceMethod, message, param)
.
logrb
in class Logger
public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String message, Object[] params)
logp(level, sourceClass, sourceMethod, message, params)
.
logrb
in class Logger
public void addHandler(Handler handler)
Handler
objects.
addHandler
in class Logger
public void removeHandler(Handler handler)
removeHandler
in class Logger
public void setUseParentHandlers(boolean useParentHandlers)
addHandler(java.util.logging.Handler)
not allowing to add any handlers, and avoid mixing
loggings from the external framework with Java loggings.
setUseParentHandlers
in class Logger
public void setParent(Logger parent)
setParent
in class Logger
public void setFilter(Filter filter)
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).
setFilter
in class Logger
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |