de.uni_paderborn.fujaba.preferences
Class LoggingPreferences

java.lang.Object
  extended byde.uni_paderborn.fujaba.preferences.AbstractPreferences
      extended byde.uni_paderborn.fujaba.preferences.LoggingPreferences

public class LoggingPreferences
extends AbstractPreferences

Singleton class containing options for log4j

To use the logging mechanism, create a static variable in your class following this pattern:

private static final Logger L = Logger.getLogger (OptionsLog4J.class);

You now have a log4j Logger (org.apache.log4j.Logger) for your class. Detailed instructions for use can be found on the log4j web site but in general, logging statements will look something like this:

if (L.isDebugEnabled()) { L.debug ("This is a log statement at debug level"); } or if (L.isInfoEnabled()) { L.info ("This is a log statement at info level"); }

NB The use of the isLEVELEnabled methods is not required, but prevents log statements being unnecessarily created if they will not be output as they are at too low a level. Please refer to the log4j documentation for further information.

Version:
$Revision: 1.6.2.3 $
Author:
$Author: mksoft $

Constructor Summary
protected LoggingPreferences()
          The private constructor for this class.
 
Method Summary
 boolean configLoaded()
          Determines whether the logging configuration has been successfully loaded
 void configureLog4J()
          Configure log4j according to options stored in this object.
 void deleteLogger(java.lang.String name)
          Delete a logger from the DOM
 void generateTestMsgs()
          Generate a message of every level to each logger to test configuration.
static LoggingPreferences get()
          This method provides the user the singleton instance of this class.
 java.lang.String getAppenderParam(java.lang.String param, java.lang.String appender)
          Gets the value of the parameter param for appender appender
 java.lang.String getAppenderPattern(java.lang.String appenderName)
          Get the conversion pattern specified for the appender whose settings are contained under appenderNode
 java.util.Collection getLoggers()
          Get a collection of objects with information on all the loggers contained within the XML file
 LoggerInfo getRootLogger()
          Gets information about the root logger
 boolean isValidLoggerName(java.lang.String name)
          Checks a String to see if it is a valid logger name
 void loadFile(java.io.File file)
          Loads a file of configuration options.
 void saveSettings()
          Save the current options to user's log4j config file.
 void setAppenderParam(java.lang.String param, java.lang.String value, java.lang.String appender)
          Sets the value of the parameter param for appender appender to value value
 void setAppenderPattern(java.lang.String pattern, java.lang.String appenderName)
          Set the conversion pattern to be used for an appender
 void setDefaults()
          Set the default options.
 void updateLogger(LoggerInfo info)
          Update the logger represented by info according to the information in info
 void updateRootLogger(LoggerInfo info)
          Updates the root logger to correspond to info
 
Methods inherited from class de.uni_paderborn.fujaba.preferences.AbstractPreferences
addPropertyChangeListener, isModified, removePropertyChangeListener, setModified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggingPreferences

protected LoggingPreferences()
The private constructor for this class. Use OptionsLog4J.get() to get an instance of this class.

See Also:
get()
Method Detail

get

public static LoggingPreferences get()
This method provides the user the singleton instance of this class.

Returns:
the singleton instance of this class

setDefaults

public void setDefaults()
Set the default options. Loads default options and then uses them to configure log4j.

Specified by:
setDefaults in class AbstractPreferences

loadFile

public void loadFile(java.io.File file)
              throws LoggingConfigException
Loads a file of configuration options.

Parameters:
file - the configuration file
Throws:
LoggingConfigException - if there are problems loading the file

configureLog4J

public void configureLog4J()
Configure log4j according to options stored in this object.


saveSettings

public void saveSettings()
Save the current options to user's log4j config file.


generateTestMsgs

public void generateTestMsgs()
Generate a message of every level to each logger to test configuration. This works on the currently loaded config - if changes were made in the GUI, the user needs to have applied them before the test will use the settings displayed there.


isValidLoggerName

public boolean isValidLoggerName(java.lang.String name)
Checks a String to see if it is a valid logger name

Parameters:
name - the name to check
Returns:
true if the name is valid, false if not

configLoaded

public boolean configLoaded()
Determines whether the logging configuration has been successfully loaded

Returns:
true if the configuration has been loaded, false otherwise

updateLogger

public void updateLogger(LoggerInfo info)
Update the logger represented by info according to the information in info

Parameters:
info - information about the logger

deleteLogger

public void deleteLogger(java.lang.String name)
Delete a logger from the DOM

Parameters:
name - the name of the logger

updateRootLogger

public void updateRootLogger(LoggerInfo info)
Updates the root logger to correspond to info

Parameters:
info - information about the root logger

getRootLogger

public LoggerInfo getRootLogger()
Gets information about the root logger

Returns:
information about the root logger

getLoggers

public java.util.Collection getLoggers()
Get a collection of objects with information on all the loggers contained within the XML file

Returns:
a collection of LoggerInfo objects representing the defined loggers

getAppenderParam

public java.lang.String getAppenderParam(java.lang.String param,
                                         java.lang.String appender)
Gets the value of the parameter param for appender appender

Parameters:
param - the name of the parameter
appender - the name of the appender
Returns:
the value of the parameter

getAppenderPattern

public java.lang.String getAppenderPattern(java.lang.String appenderName)
Get the conversion pattern specified for the appender whose settings are contained under appenderNode

Parameters:
appenderName - the name of the appender
Returns:
the conversion pattern

setAppenderParam

public void setAppenderParam(java.lang.String param,
                             java.lang.String value,
                             java.lang.String appender)
Sets the value of the parameter param for appender appender to value value

Parameters:
param - the name of the parameter
value - the value to set the parameter to
appender - the name of the appender which the parameter is for

setAppenderPattern

public void setAppenderPattern(java.lang.String pattern,
                               java.lang.String appenderName)
Set the conversion pattern to be used for an appender

Parameters:
pattern - the pattern to be used
appenderName - the name of the appender