|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.uni_paderborn.fujaba.preferences.AbstractPreferences
de.uni_paderborn.fujaba.preferences.LoggingPreferences
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.
Field Summary | |
private java.util.Hashtable |
appenderCache
Cache of appender nodes for appender names |
private java.lang.String |
configFile
The file which the log4j options are stored in NB: Changed to follow .fujabarc |
private java.lang.String |
defaultConfigFile
The file to load default options from if the user's config file is not available |
private org.w3c.dom.Document |
log4JConfig
The DOM Document containing the options for log4j. |
private static LoggingPreferences |
options
The instance of this singleton class. |
Fields inherited from class de.uni_paderborn.fujaba.preferences.AbstractPreferences |
|
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. |
private org.w3c.dom.Node |
getAppenderNode(java.lang.String name)
Gets the node in the log4j DOM representing the appender with name name |
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 |
private org.w3c.dom.Node |
getLoggerNode(java.lang.String name)
Gets the node representing a logger of a certain name |
java.util.Collection |
getLoggers()
Get a collection of objects with information on all the loggers contained within the XML file |
private java.lang.String |
getParam(java.lang.String name,
org.w3c.dom.Node node)
Gets the value of the parameter name under node |
LoggerInfo |
getRootLogger()
Gets information about the root logger |
private void |
initWithDefaults()
Tries to initialise the mechanism using the default settings, and takes appropriate action if this is not possible. |
private org.w3c.dom.Element |
insertElement(org.w3c.dom.Element parent,
java.lang.String name,
java.util.Map atts,
java.util.List successors)
Insert an element into the DOM tree |
boolean |
isValidLoggerName(java.lang.String name)
Checks a String to see if it is a valid logger name |
private void |
loadDefaults()
Load the default log4j settings. |
void |
loadFile(java.io.File file)
Loads a file of configuration options. |
private org.w3c.dom.Document |
parse(java.io.InputStream xmlStream,
org.xml.sax.ErrorHandler handler)
Parse xmlFile to retrieve a Document |
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. |
private void |
setParam(java.lang.String name,
java.lang.String value,
org.w3c.dom.Node node)
Set the value of a parameter. |
private java.lang.String |
subst(java.lang.String val)
Use the log4j method for replacing system properties found in the string |
private void |
testLogger(org.apache.log4j.Logger logger)
Make a test call at each level to a specified logger |
void |
updateLogger(LoggerInfo info)
Update the logger represented by info according to the information in info |
private void |
updateLoggerNode(org.w3c.dom.Node node,
LoggerInfo info)
Updates the level element in node to correspond to 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 |
Field Detail |
private static LoggingPreferences options
get()
private org.w3c.dom.Document log4JConfig
private java.lang.String configFile
private java.lang.String defaultConfigFile
private java.util.Hashtable appenderCache
Constructor Detail |
protected LoggingPreferences()
get()
Method Detail |
private void initWithDefaults()
public static LoggingPreferences get()
public void setDefaults()
setDefaults
in class AbstractPreferences
public void loadFile(java.io.File file) throws LoggingConfigException
file
- the configuration file
LoggingConfigException
- if there are problems loading the filepublic void configureLog4J()
public void saveSettings()
public void generateTestMsgs()
private void testLogger(org.apache.log4j.Logger logger)
logger
- the logger to testpublic boolean isValidLoggerName(java.lang.String name)
name
- the name to check
true
if the name is valid, false
if notprivate void loadDefaults() throws LoggingConfigException
LoggingConfigException
- if there is a problem whilst loading the default optionsprivate org.w3c.dom.Document parse(java.io.InputStream xmlStream, org.xml.sax.ErrorHandler handler) throws java.io.IOException, org.xml.sax.SAXException
xmlFile
to retrieve a Document
xmlStream
- an open stream to XML data to parsehandler
- the handler the parser should use
java.io.IOException
- if there is an I/O problem whilst opening or reading from the file
org.xml.sax.SAXException
- if there is a parsing errorpublic boolean configLoaded()
true
if the configuration has been loaded, false
otherwisepublic void updateLogger(LoggerInfo info)
info
according to the information in info
info
- information about the loggerpublic void deleteLogger(java.lang.String name)
name
- the name of the loggerpublic void updateRootLogger(LoggerInfo info)
info
info
- information about the root loggerprivate org.w3c.dom.Node getLoggerNode(java.lang.String name)
name
- the name of the logger
private void updateLoggerNode(org.w3c.dom.Node node, LoggerInfo info)
node
to correspond to info
node
- the node to updateinfo
- corresponding logger infoprivate org.w3c.dom.Element insertElement(org.w3c.dom.Element parent, java.lang.String name, java.util.Map atts, java.util.List successors) throws org.w3c.dom.DOMException
parent
- the parent of the new elementname
- the name of the new elementatts
- any attributes the new element should havesuccessors
- a list of names of elements which may be found after the new element
(to guide positioning)
org.w3c.dom.DOMException
- if something goes wrongpublic LoggerInfo getRootLogger()
public java.util.Collection getLoggers()
public java.lang.String getAppenderParam(java.lang.String param, java.lang.String appender)
param
for appender appender
param
- the name of the parameterappender
- the name of the appender
public java.lang.String getAppenderPattern(java.lang.String appenderName)
appenderNode
appenderName
- the name of the appender
public void setAppenderParam(java.lang.String param, java.lang.String value, java.lang.String appender)
param
for appender appender
to value value
param
- the name of the parametervalue
- the value to set the parameter toappender
- the name of the appender which the parameter is forpublic void setAppenderPattern(java.lang.String pattern, java.lang.String appenderName)
pattern
- the pattern to be usedappenderName
- the name of the appenderprivate org.w3c.dom.Node getAppenderNode(java.lang.String name)
name
name
- the name of the appender
private java.lang.String getParam(java.lang.String name, org.w3c.dom.Node node)
name
under node
name
- the name of the parameternode
- the node under which the parameter is to be found
private void setParam(java.lang.String name, java.lang.String value, org.w3c.dom.Node node)
name
- the name of the parametervalue
- the value to set the parameter tonode
- the node under which the parameter is to be foundprivate java.lang.String subst(java.lang.String val)
val
- the String object to examine
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |