Class WrappingLogger
- java.lang.Object
-
- java.util.logging.Logger
-
- de.aristaflow.adept2.util.logging.WrappingLogger
-
- Direct Known Subclasses:
DebugLogger
,NameWrappingLogger
public class WrappingLogger extends Logger
This logger wraps a normal logger and handles setting the log level appropriately. This allows for easy wrapping and extending a logger.
This logger may have a different name than the wrapped logger.Logging is only forwarded to the wrapped logger in case this
logs
for the level of the current record. Otherwise logging is done by this logger.- Author:
- Ulrich Kreher
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
innerLogger
The wrapped logger.-
Fields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
WrappingLogger(String name, Logger innerLogger)
Creates a new logger wrapping the designated one and having the designated name.protected
WrappingLogger(Logger innerLogger)
Creates a new logger wrapping the designated one.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHandler(Handler handler)
boolean
equals(Object obj)
Callsequals(Object)
of the inner logger.Filter
getFilter()
Handler[]
getHandlers()
Level
getLevel()
String
getName()
Logger
getParent()
ResourceBundle
getResourceBundle()
String
getResourceBundleName()
boolean
getUseParentHandlers()
int
hashCode()
boolean
isLoggable(Level level)
Since this method delegates to the inner logger, it usually has to be overridden in case (a subclass of) this logger sets the level without propagating it to the wrapped logger.void
log(LogRecord record)
Logs the designated record by the wrapped logger in case the wrapped logger logs the corresponding level.void
removeHandler(Handler handler)
void
setFilter(Filter newFilter)
void
setLevel(Level newLevel)
protected void
setLevel(Level newLevel, boolean propagate)
Sets the level of this logger to the designated one.void
setParent(Logger parent)
void
setUseParentHandlers(boolean useParentHandlers)
-
Methods inherited from class java.util.logging.Logger
config, config, entering, entering, entering, exiting, exiting, fine, fine, finer, finer, finest, finest, getAnonymousLogger, getAnonymousLogger, getGlobal, getLogger, getLogger, info, info, log, log, log, log, log, log, logp, logp, logp, logp, logp, logp, logrb, logrb, logrb, logrb, logrb, logrb, logrb, logrb, setResourceBundle, severe, severe, throwing, warning, warning
-
-
-
-
Field Detail
-
innerLogger
protected final Logger innerLogger
The wrapped logger.
-
-
Constructor Detail
-
WrappingLogger
protected WrappingLogger(Logger innerLogger)
Creates a new logger wrapping the designated one. The created logger will have the same name as the wrapped logger.- Parameters:
innerLogger
- The logger to which all requests will be forwarded.
-
WrappingLogger
protected WrappingLogger(String name, Logger innerLogger)
Creates a new logger wrapping the designated one and having the designated name.- Parameters:
innerLogger
- The logger to which all requests will be forwarded.name
- The name of the logger (this). This name is used in log records.
-
-
Method Detail
-
getResourceBundle
public ResourceBundle getResourceBundle()
- Overrides:
getResourceBundle
in classLogger
-
getResourceBundleName
public String getResourceBundleName()
- Overrides:
getResourceBundleName
in classLogger
-
setFilter
public void setFilter(Filter newFilter) throws SecurityException
- Overrides:
setFilter
in classLogger
- Throws:
SecurityException
-
setLevel
public void setLevel(Level newLevel) throws SecurityException
- Overrides:
setLevel
in classLogger
- Throws:
SecurityException
-
setLevel
protected void setLevel(Level newLevel, boolean propagate)
Sets the level of this logger to the designated one. The designated level may be propagated to the wrapped logger. This propagation may change the effective level (due to the level of parent loggers). In this case the level of this logger will be set appropriately to the effective level.- Parameters:
newLevel
- The level to set in this logger.propagate
- Whether the designated level should be propagated to the wrapped logger.
-
isLoggable
public boolean isLoggable(Level level)
Since this method delegates to the inner logger, it usually has to be overridden in case (a subclass of) this logger sets the level without propagating it to the wrapped logger.- Overrides:
isLoggable
in classLogger
-
addHandler
public void addHandler(Handler handler) throws SecurityException
- Overrides:
addHandler
in classLogger
- Throws:
SecurityException
-
removeHandler
public void removeHandler(Handler handler) throws SecurityException
- Overrides:
removeHandler
in classLogger
- Throws:
SecurityException
-
getHandlers
public Handler[] getHandlers()
- Overrides:
getHandlers
in classLogger
-
setUseParentHandlers
public void setUseParentHandlers(boolean useParentHandlers)
- Overrides:
setUseParentHandlers
in classLogger
-
getUseParentHandlers
public boolean getUseParentHandlers()
- Overrides:
getUseParentHandlers
in classLogger
-
log
public void log(LogRecord record)
Logs the designated record by the wrapped logger in case the wrapped logger logs the corresponding level. Otherwise the record is logged by the wrapping logger.
-
equals
public boolean equals(Object obj)
Callsequals(Object)
of the inner logger. However, the designated object will be unwrapped if it is also aWrappingLogger
.
-
-