|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.fhg.igd.logging.LoggingConfiguration
This class allows easy maintenance and configuration of the logging
framework at runtime. For this purpose, a set of convenience methods is
being provided. Additionally, the main
method supports a
similar set of command line options. Detailed information is available
via the help
printout:
On initialization, the current configuration will be read from a
file whose name will be looked up in the Java system property
de.fhg.igd.logging.config
.
If the system property is not defined or the specified destination file
cannot be read, the initialization will look for the resource file
de/fhg/igd/logging/logging.properties
instead.
In case both attempts (system property and system resource) fail,
the default configuration
will be loaded.
Within the logging configuration file the following properties are supported:
setLogger(java.lang.String)
for the list of valid <logger>
values and further information.
setInterval(String)
for the list of valid
<interval> values and further information.
setBuffer(String,String)
for the list of valid
<buffer> values and further information.
addOutput(String,String)
for further information.
setLogLevel(String,String)
for the list of valid
<loglevel> values and further information.
NOTICE:
Field Summary | |
static String |
CONFIG_FILE_PROPERTY
The name of the system property that contains the path to the logging configuration file |
static String |
CONFIG_RESOURCE
The name of the resource file that will be loaded instead of an undefined or missing logging configuration file |
protected Set |
configurationChangeListeners_
The storage for registered ConfigurationChangeListener objects |
static String |
CR
The system dependent line separator |
protected static LoggingConfiguration |
instance_
The singleton instance |
protected ConfigurationParameters |
parameters_
The configuration parameters |
Constructor Summary | |
private |
LoggingConfiguration()
Hidden construction. |
Method Summary | |
void |
addConfigurationChangeListener(ConfigurationChangeListener listener)
Register for configuration change notifications |
boolean |
addOutput(String name,
String output)
Add an output destination URL . |
boolean |
addOutput(String name,
URL output)
|
void |
apply(ConfigurationParameters parameters)
Apply the given configuration by trying to minimize changes in order to keep alive as many output connections as possible. |
static LoggingConfiguration |
atPresent()
Get the current configuration. |
protected static void |
checkOutput(URL output)
Check the given output destination URL by trying
to establish a connection and closing the stream right after. |
protected String |
findBestName(String target)
|
private void |
fireBufferChanged(URL url,
Integer oldval,
Integer newval)
Fire an appropriate ConfigurationChangeEvent to
ConfigurationChangeListener.bufferChanged(de.fhg.igd.logging.ConfigurationChangeEvent) of all
registered listener objects. |
private void |
fireIntervalChanged(Long oldval,
Long newval)
Fire an appropriate ConfigurationChangeEvent to
ConfigurationChangeListener.intervalChanged(de.fhg.igd.logging.ConfigurationChangeEvent) of all
registered listener objects. |
private void |
fireLoggerChanged(String oldval,
String newval)
Fire an appropriate ConfigurationChangeEvent to
ConfigurationChangeListener.loggerChanged(de.fhg.igd.logging.ConfigurationChangeEvent) of all
registered listener objects. |
private void |
fireLogLevelChanged(String name,
LogLevel oldval,
LogLevel newval)
Fire an appropriate ConfigurationChangeEvent to
ConfigurationChangeListener.logLevelChanged(de.fhg.igd.logging.ConfigurationChangeEvent) of all
registered listener objects. |
private void |
fireOutputChanged(String name,
Object oldval,
Object newval)
Fire an appropriate ConfigurationChangeEvent to
ConfigurationChangeListener.outputChanged(de.fhg.igd.logging.ConfigurationChangeEvent) of all
registered listener objects. |
Integer |
getBuffer(URL output)
Get the buffer value of an output destination URL . |
Long |
getInterval()
Get the current interval value. |
String |
getLogger()
Get the current logger property value. |
ConfigurationParameters.BestMatch |
getLogLevel(String name)
Get the log level of a logger by its package name. |
ConfigurationParameters.BestMatch |
getOutput(String name)
Get all output URL s for the specified name. |
void |
help()
Print out some information about available command line options. |
protected void |
init()
Initialize the current configuration by first trying to read the logging configuration file defined in the system property . |
String |
list(String name)
Get a printout of all properties for a specific class/package name. |
void |
load(InputStream is)
Reinitialize the current configuration from a stream. |
void |
load(String file)
Reinitialize the current configuration from a file. |
static void |
main(String[] args)
Provides a CommandLineInterface which publishes
almost all public methods. |
void |
reinit()
|
void |
removeConfigurationChangeListener(ConfigurationChangeListener listener)
Deregister from configuration change notifications |
boolean |
removeOutput(String name)
Remove all output destinations of the given name. |
boolean |
removeOutput(String name,
String output)
Remove an output destination. |
boolean |
removeOutput(String name,
URL output)
|
void |
save(OutputStream os)
Write the current configuration to a stream. |
void |
save(String file)
Write the current configuration to a file. |
boolean |
setBuffer(String output,
String buffer)
Set the buffer property for a specific output destination. |
boolean |
setBuffer(URL output,
Integer buffer)
|
boolean |
setInterval(Long interval)
|
boolean |
setInterval(String interval)
Change the interval property. |
boolean |
setLogger(String logger)
Change the logger property. |
boolean |
setLogLevel(String name,
LogLevel loglevel)
|
boolean |
setLogLevel(String name,
String loglevel)
Set the loglevel property of a specific class/package name. |
boolean |
unsetBuffer(String output)
Unset the buffer property of a specific output destination. |
boolean |
unsetBuffer(URL output)
|
boolean |
unsetLogLevel(String name)
Unset the loglevel property of a specific class/package name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String CONFIG_FILE_PROPERTY
public static final String CONFIG_RESOURCE
public static final String CR
protected Set configurationChangeListeners_
ConfigurationChangeListener
objects
protected ConfigurationParameters parameters_
protected static LoggingConfiguration instance_
Constructor Detail |
private LoggingConfiguration()
Method Detail |
protected void init()
system property
.
If the system property is not defined or loading the configuration
fails, try to read the resource file
.
In case initialization even with the system resource file fails,
load the
default configuration
.
public static LoggingConfiguration atPresent()
public void load(String file)
file
- The file to load the logging configuration from
IllegalArgumentException
- if the file name is null
or empty
LoggingException
- if initializing the configuration failedpublic void load(InputStream is)
is
- The stream to load the logging configuration from
IllegalArgumentException
- if the argument is null
LoggingException
- if initializing the configuration failedpublic void save(String file)
file
- The target logging configuration file
IllegalArgumentException
- if the argument is null
or empty
LoggingException
- in case the logging configuration file could
not be writtenpublic void save(OutputStream os)
os
- The target stream
IllegalArgumentException
- if the argument is null
public void apply(ConfigurationParameters parameters)
parameters
- The new configuration parameters
IllegalArgumentException
- if the argument is null
public void reinit()
init()
public boolean setLogger(String logger)
logger
- The new logger value (as to be used in the
logging configuration file), which might be as follows:
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given value
IllegalArgumentException
- if the argument is null
LoggingException
- in case the requested property value could not
be changedpublic String getLogger()
public boolean setInterval(String interval)
interval
- The new interval value (as to be used in the
logging configuration file), which might be as follows:
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given valuepublic boolean setInterval(Long interval)
IllegalArgumentException
- if the argument is null
or less than zerosetInterval(String)
public Long getInterval()
public boolean setBuffer(String output, String buffer)
output
- The output destination URL
to set the
buffer forbuffer
- The new buffer property value (as to be used
in the logging configuration file), which might be as follows:
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given valuepublic boolean setBuffer(URL output, Integer buffer)
IllegalArgumentException
- if any argument is null
or the buffer size is less than zero
LoggingException
- in case the requested property value could not
be setsetBuffer(String,String)
public boolean unsetBuffer(String output)
output
- The output destination URL
to unset the
buffer for
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given valuepublic boolean unsetBuffer(URL output)
IllegalArgumentException
- if the argument is null
LoggingException
- in case the requested property value could not
be unsetunsetBuffer(String)
public Integer getBuffer(URL output)
URL
.
In case there is no buffer value configured for the given
URL
, the default value (which depends on the protocol
identifier) will be returned.
output
- The corresponding URL
URL
public boolean addOutput(String name, String output)
URL
.
In case an exception is thrown while trying to apply the requested
property value changes, the previous configuration will be restored.
name
- The class/package name to add the new output
destination tooutput
- The new output destination URL
To configure the root logger, simply omit the package name. The root
logger always needs to be configured. If omitted, the default will
be used. The default value is: file:///./default.log
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given valuepublic boolean addOutput(String name, URL output)
IllegalArgumentException
- if any argument is null
LoggingException
- in case the requested property value could not
be addedaddOutput(String,String)
public boolean removeOutput(String name, String output)
name
- The class/package name to remove the output
destination fromoutput
- The output destination URL
to be removed
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given valuepublic boolean removeOutput(String name, URL output)
IllegalArgumentException
- if any argument is null
or
on the attempt to remove the last output URL
of
the root entry
LoggingException
- in case the requested property value could not
be removedremoveOutput(String,String)
public boolean removeOutput(String name)
Notice: In case an exception is thrown while trying to apply necessary property value changes, the previous configuration will not be restored.
name
- The class/package name to remove all output
destinations from
true
if all output destinations have been
removed successfully, false
if at least one output
destination could not be removed
IllegalArgumentException
- if the argument is null
public ConfigurationParameters.BestMatch getOutput(String name)
URL
s for the specified name. If there
are none defined for the given name, find the closest match.
name
- The name to search the output URLs for
Set
of output destination URL
objectspublic boolean setLogLevel(String name, String loglevel)
name
- The class/package name to set the log level forloglevel
- The new loglevel value (as to be used in the
logging configuration file), which might be as follows:
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given valuepublic boolean setLogLevel(String name, LogLevel loglevel)
IllegalArgumentException
- if any argument is null
LoggingException
- in case the requested property value could not
be setsetLogLevel(String,String)
public boolean unsetLogLevel(String name)
name
- The class/package name to unset the log level for
true
if the property value has been
changed successfully, false
if the property value
did not need to be changed since it is already equal to the
given value
IllegalArgumentException
- if the argument is null
on
the attempt to remove the root loglevel
LoggingException
- in case the requested property value could not
be unsetpublic ConfigurationParameters.BestMatch getLogLevel(String name)
name
- The name to search the log level for
LogLevel
objectpublic String list(String name)
name
- The class/package name to get the printout for
protected String findBestName(String target)
ConfigurationParameters.findBestName(String)
protected static void checkOutput(URL output)
URL
by trying
to establish a connection and closing the stream right after.
output
- The output destination URL
to test
LoggingException
- if establishing the connection failed
NullPointerException
- if the output URL
is
null
public void help()
public void addConfigurationChangeListener(ConfigurationChangeListener listener)
public void removeConfigurationChangeListener(ConfigurationChangeListener listener)
private void fireLoggerChanged(String oldval, String newval)
ConfigurationChangeEvent
to
ConfigurationChangeListener.loggerChanged(de.fhg.igd.logging.ConfigurationChangeEvent)
of all
registered listener objects.
oldval
- The previous logger property valuenewval
- The new logger property valueprivate void fireIntervalChanged(Long oldval, Long newval)
ConfigurationChangeEvent
to
ConfigurationChangeListener.intervalChanged(de.fhg.igd.logging.ConfigurationChangeEvent)
of all
registered listener objects.
oldval
- The previous interval property valuenewval
- The new interval property valueprivate void fireBufferChanged(URL url, Integer oldval, Integer newval)
ConfigurationChangeEvent
to
ConfigurationChangeListener.bufferChanged(de.fhg.igd.logging.ConfigurationChangeEvent)
of all
registered listener objects.
url
- The URL
of the changed buffer valueoldval
- The previous buffer property valuenewval
- The current buffer property valueprivate void fireOutputChanged(String name, Object oldval, Object newval)
ConfigurationChangeEvent
to
ConfigurationChangeListener.outputChanged(de.fhg.igd.logging.ConfigurationChangeEvent)
of all
registered listener objects.
name
- The class/package name of the changed output destination
URL
oldval
- The previous output destination(s);
in case a new URL
(to be found in curval) has been
added, or null
if there were no output destinations
defined yet, or a Set
of previously assigned
URL
s for the given name; if a single URL
,
this one has been removed (possibly remaining destinations may be
found in newval)newval
- The current output destination(s);
in case an existing URL
(to be found in preval) has
been removed, or null
if there are no output
destinations defined anymore, or a Set
of remaining
URL
s for the given name; if a single URL
,
this one has been added (previously existing destinations may be
found in preval)private void fireLogLevelChanged(String name, LogLevel oldval, LogLevel newval)
ConfigurationChangeEvent
to
ConfigurationChangeListener.logLevelChanged(de.fhg.igd.logging.ConfigurationChangeEvent)
of all
registered listener objects.
name
- The class/package name of the changed LogLevel
oldval
- The previous loglevel property value of the
given namenewval
- The current loglevel property value of the
given namepublic static void main(String[] args)
CommandLineInterface
which publishes
almost all public methods. For more information just run
args
- The command line arguments
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |