public abstract class LoggerAdapter extends Logger
severe
, warning
,
info
, config
, fine
,
finer
and finest
methods as abstract
ones. Subclasses should implement those methods in order to map JDK logging levels to
the backend logging framework.
All log
methods are overridden in order to redirect to one of the
above-cited methods. Note that this is the opposite approach than the JDK logging framework
one, which implements 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
.
Logger
are disabled:
addHandler(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 JDK loggings.setParent(Logger)
since this adapter should not inherits any configuration from a parent logger using the
JDK logging framework.setFilter(Filter)
for keeping this LoggerAdapter
simple.LoggerAdapter
s do not hold any configuration by themselves, 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.
logrb
or log(LogRecord)
methods. This is sufficient for
SIS 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.
FINE
and FINER
, then the finer
method will be invoked. See isLoggable(Level)
for implementation tips taking advantage
of this rule.Logging
Defined in the sis-utility
module
global, GLOBAL_LOGGER_NAME
Modifier | Constructor and Description |
---|---|
protected |
LoggerAdapter(String name)
Creates a new logger.
|
Modifier and Type | Method and Description |
---|---|
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()
|
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,
ResourceBundle bundle,
String message,
Object... params)
Logs a localizable record at the specified level.
|
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
ResourceBundle bundle,
String message,
Throwable thrown)
Logs a localizable record at the specified level.
|
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message)
Deprecated.
JDK 8 has deprecated this method.
|
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message,
Object param)
Deprecated.
JDK 8 has deprecated this method.
|
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message,
Object[] params)
Deprecated.
JDK 8 has deprecated this method.
|
void |
logrb(Level level,
String sourceClass,
String sourceMethod,
String bundleName,
String message,
Throwable thrown)
Deprecated.
JDK 8 has deprecated this method.
|
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. |
config, fine, finer, finest, getAnonymousLogger, getAnonymousLogger, getFilter, getGlobal, getHandlers, getLogger, getLogger, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers, info, log, log, logp, logp, setResourceBundle, severe, warning
protected LoggerAdapter(String name)
name
- the logger name.public abstract void setLevel(Level level)
public abstract Level getLevel()
@Debug protected Level getDebugLevel()
entering(…)
, exiting(…)
and throwing(…)
methods.
The default implementation returns Level.FINER
, which is consistent with the
value used in the JDK 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.
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).
public boolean isLoggable(Level level) { final int n = level.intValue(); switch (n / 100) { default: { // MAX_VALUE is a special value for Level.OFF. Otherwise and // if positive, fallthrough since we are greater than SEVERE. switch (n) { case Integer.MIN_VALUE: return true; // Level.ALL case Integer.MAX_VALUE: return false; // Level.OFF default: if (n < 0) return false; } } case 10: return isSevereEnabled(); case 9: return isWarningEnabled(); case 8: return isInfoEnabled(); case 7: return isConfigEnabled(); case 6: // fallthrough case 5: return isFineEnabled(); case 4: return isFinerEnabled(); case 3: return isFinestEnabled(); case 2: // fallthrough case 1: // fallthrough case 0: return false; } }
isLoggable
in class Logger
level
- a message logging level.true
if the given message level is currently being logged.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.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.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.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.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.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.public void log(LogRecord record)
logrb
or
logp(Level,String,String,String)
methods.public void log(Level level, String message, Throwable thrown)
log(level, message)
.public void log(Level level, String message, Object param)
log(level, message, params)
where the params
array is built from the param
object.public void log(Level level, String message, Object[] params)
log(level, message)
.public void logp(Level level, String sourceClass, String sourceMethod, String message)
log(level, message)
.public void logp(Level level, String sourceClass, String sourceMethod, String message, Throwable thrown)
log(level, message, thrown)
.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 discarded unless the
target logp
method has been overridden.
public void logp(Level level, String sourceClass, String sourceMethod, String message, Object[] params)
public void logrb(Level level, String sourceClass, String sourceMethod, ResourceBundle bundle, String message, Object... params)
logp(level, sourceClass, sourceMethod, message, params)
.logrb
in class Logger
level
- one of the message level identifiers.sourceClass
- name of class that issued the logging request.sourceMethod
- name of the method.bundle
- the resource bundle for localizing the message, or null
.message
- the message to log.params
- array of parameters to the method being entered.public void logrb(Level level, String sourceClass, String sourceMethod, ResourceBundle bundle, String message, Throwable thrown)
logp(level, sourceClass, sourceMethod, message, thrown)
.logrb
in class Logger
level
- one of the message level identifiers.sourceClass
- name of class that issued the logging request.sourceMethod
- name of the method.bundle
- the resource bundle for localizing the message, or null
.message
- the message to log.thrown
- throwable associated with log message.@Deprecated public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String message)
logp(level, sourceClass, sourceMethod, message)
.@Deprecated 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
level
- one of the message level identifiers.sourceClass
- name of class that issued the logging request.sourceMethod
- name of the method.bundleName
- name of resource bundle to localize message, or null
.message
- the message to log.thrown
- throwable associated with log message.@Deprecated 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
level
- one of the message level identifiers.sourceClass
- name of class that issued the logging request.sourceMethod
- name of the method.bundleName
- name of resource bundle to localize message, or null
.message
- the message to log.param
- parameter to the method being entered.@Deprecated 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
level
- one of the message level identifiers.sourceClass
- name of class that issued the logging request.sourceMethod
- name of the method.bundleName
- name of resource bundle to localize message, or null
.message
- the message to log.params
- array of parameters to the method being entered.public void addHandler(Handler handler)
Handler
objects.addHandler
in class Logger
handler
- a logging handler, ignored in default implementation.public void removeHandler(Handler handler)
removeHandler
in class Logger
handler
- a logging handler, ignored in default implementation.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 JDK loggings.setUseParentHandlers
in class Logger
useParentHandlers
- ignored in default implementation.public void setParent(Logger parent)
setParent
in class Logger
parent
- ignored in default implementation.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
filter
- ignored in default implementation.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.