public class ConfigurationLogger extends Object
A class providing basic logging capabilities.
When reading configuration files in complex scenarios having log output is useful for diagnostic purposes. Therefore,
Commons Configuration produces some logging output. As concrete projects have different requirements on the
amount and detail of logging, there is a way of configuring logging: All classes derived from
AbstractConfiguration
can be assigned a logger which is then used for all
log statements generated.
Allowing a logger object to be passed to a configuration creates a direct dependency to a concrete logging framework
in the configuration API. This would make it impossible to switch to an alternative logging framework without
breaking backwards compatibility. To avoid this, the ConfigurationLogger
class is introduced. It is a minimum
abstraction over a logging framework offering only very basic logging capabilities. The methods defined in this class
are used by configuration implementations to produce their logging statements. Client applications can create
specialized instances and pass them to configuration objects without having to deal with a concrete logging
framework. It is even possible to create a subclass that uses a completely different logging framework.
Modifier | Constructor and Description |
---|---|
protected |
ConfigurationLogger()
Creates a new, uninitialized instance of
ConfigurationLogger . |
|
ConfigurationLogger(Class<?> logCls)
Creates a new instance of
ConfigurationLogger that uses a logger whose name is derived from the provided
class. |
|
ConfigurationLogger(String loggerName)
Creates a new instance of
ConfigurationLogger that uses the specified logger name. |
Modifier and Type | Method and Description |
---|---|
void |
debug(String msg)
Logs the specified message on debug level.
|
void |
error(String msg)
Logs the specified message on error level.
|
void |
error(String msg,
Throwable ex)
Logs the specified exception on error level.
|
void |
info(String msg)
Logs the specified message on info level.
|
boolean |
isDebugEnabled()
Returns a flag whether logging on debug level is enabled.
|
boolean |
isInfoEnabled()
Returns a flag whether logging on info level is enabled.
|
static ConfigurationLogger |
newDummyLogger()
Creates a new dummy logger which produces no output.
|
void |
warn(String msg)
Logs the specified message on warn level.
|
void |
warn(String msg,
Throwable ex)
Logs the specified exception on warn level.
|
public ConfigurationLogger(String loggerName)
ConfigurationLogger
that uses the specified logger name.loggerName
- the logger name (must not be null)IllegalArgumentException
- if the logger name is nullpublic ConfigurationLogger(Class<?> logCls)
ConfigurationLogger
that uses a logger whose name is derived from the provided
class.logCls
- the class whose name is to be used for logging (must not be null)IllegalArgumentException
- if the logger class is nullprotected ConfigurationLogger()
ConfigurationLogger
. This constructor can be used by derived classes
that implement their own specific logging mechanism. Such classes must override all methods because the default
implementations do not work in this uninitialized state.public static ConfigurationLogger newDummyLogger()
public boolean isDebugEnabled()
public void debug(String msg)
msg
- the message to be loggedpublic boolean isInfoEnabled()
public void info(String msg)
msg
- the message to be loggedpublic void warn(String msg)
msg
- the message to be loggedpublic void warn(String msg, Throwable ex)
msg
- the message to be loggedex
- the exception to be loggedpublic void error(String msg)
msg
- the message to be loggedCopyright © 2001–2022 The Apache Software Foundation. All rights reserved.