com.bristle.javalib.log
Class XMLDOMLoggerTarget

java.lang.Object
  extended by com.bristle.javalib.log.XMLDOMLoggerTarget
All Implemented Interfaces:
Logger.LoggerTarget

public class XMLDOMLoggerTarget
extends Object
implements Logger.LoggerTarget

This class implements the Logger.LoggerTarget interface, writing log entries to an XML DOM.

Usage:
   - See the Logger class.

   - See the source code of the inner Tester class for more examples.
  
Assumptions:
Effects:
- Adds nodes to the XML DOM with the following structure: <Log> <Entry> <DateTime>2007/02/16 18:14:25.274 Fri</DateTime> <AppName>MyApp</AppName> <AppVersion>v1.0</AppVersion> <Username>STLUKF00</Username> <ThreadName>[Thread-12]</ThreadName> <Millisecs>1171667665274</Millisecs> <UsedMem>23510888</UsedMem> <TotalMem>27770872</TotalMem> <Level>1</Level> <Msg>This is a sample log message.</Msg> </Entry> ... </Log> Where: <DateTime> is the current date and time on the server in format: yyyy/MM/dd HH:mm:ss.SSS EEE For example: 2007/12/31 23:59:59.999 Mon <AppName> is the name of the application that called the logger. <AppVersion> is the version string of the application. <Username> is the name of the current user. <ThreadName> is the name of the current thread. <Millisecs> is the current time in milliseconds on the server. <UsedMem> is the current number of bytes of used memory in the JVM of the Web Server. <TotalMem> is the current number of bytes of total memory in the JVM of the Web Server. <Level> indicates the logging level of the message. Can be used as an indentation level to format the messages. <Msg> is the text of the message.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class XMLDOMLoggerTarget.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Field Summary
private  String m_strXMLAppNameTag
           
private  String m_strXMLAppVersionTag
           
private  String m_strXMLDateTimeTag
           
private  String m_strXMLEntryTag
           
private  String m_strXMLLevelTag
           
private  String m_strXMLMillisecsTag
           
private  String m_strXMLMsgTag
           
private  String m_strXMLRootTag
           
private  String m_strXMLThreadNameTag
           
private  String m_strXMLTotalMemTag
           
private  String m_strXMLUsedMemTag
           
private  String m_strXMLUsernameTag
           
private  Document m_xmlDOM
           
 
Constructor Summary
XMLDOMLoggerTarget(Document xmlDOM)
          Constructor.
 
Method Summary
 String getXMLAppNameTag()
          Get the XML tag used for "AppName" nodes.
 String getXMLAppVersionTag()
          Get the XML tag used for "AppVersion" nodes.
 String getXMLDateTimeTag()
          Get the XML tag used for "DateTime" nodes.
 Document getXMLDOM()
          Get the XML DOM that messages are currently being logged to.
 String getXMLEntryTag()
          Get the XML tag used for "Entry" nodes.
 String getXMLLevelTag()
          Get the XML tag used for "Level" nodes.
 String getXMLMillisecsTag()
          Get the XML tag used for "Millisecs" nodes.
 String getXMLMsgTag()
          Get the XML tag used for "Msg" nodes.
 String getXMLRootTag()
          Get the XML root tag.
 String getXMLThreadNameTag()
          Get the XML tag used for "ThreadName" nodes.
 String getXMLTotalMemTag()
          Get the XML tag used for "TotalMem" nodes.
 String getXMLUsedMemTag()
          Get the XML tag used for "UsedMem" nodes.
 String getXMLUsernameTag()
          Get the XML tag used for "Username" nodes.
 void log(Logger.Entry entry)
          Log the log entry to the XML DOM.
 void setXMLAppNameTag(String strNew)
          Set the XML tag used for "AppName" nodes.
 void setXMLAppVersionTag(String strNew)
          Set the XML tag used for "AppVersion" nodes.
 void setXMLDateTimeTag(String strNew)
          Set the XML tag used for "DateTime" nodes.
 void setXMLDOM(Document xmlDOM)
          Set the XML DOM to write log entries to.
 void setXMLEntryTag(String strNew)
          Set the XML tag used for "Entry" nodes.
 void setXMLLevelTag(String strNew)
          Set the XML tag used for "Level" nodes.
 void setXMLMillisecsTag(String strNew)
          Set the XML tag used for "Millisecs" nodes.
 void setXMLMsgTag(String strNew)
          Set the XML tag used for "Msg" nodes.
 void setXMLRootTag(String strNew)
          Set the XML root tag.
 void setXMLThreadNameTag(String strNew)
          Set the XML tag used for "ThreadName" nodes.
 void setXMLTotalMemTag(String strNew)
          Set the XML tag used for "TotalMem" nodes.
 void setXMLUsedMemTag(String strNew)
          Set the XML tag used for "UsedMem" nodes.
 void setXMLUsernameTag(String strNew)
          Set the XML tag used for "Username" nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_xmlDOM

private Document m_xmlDOM

m_strXMLRootTag

private String m_strXMLRootTag

m_strXMLEntryTag

private String m_strXMLEntryTag

m_strXMLDateTimeTag

private String m_strXMLDateTimeTag

m_strXMLAppNameTag

private String m_strXMLAppNameTag

m_strXMLAppVersionTag

private String m_strXMLAppVersionTag

m_strXMLUsernameTag

private String m_strXMLUsernameTag

m_strXMLThreadNameTag

private String m_strXMLThreadNameTag

m_strXMLMillisecsTag

private String m_strXMLMillisecsTag

m_strXMLUsedMemTag

private String m_strXMLUsedMemTag

m_strXMLTotalMemTag

private String m_strXMLTotalMemTag

m_strXMLLevelTag

private String m_strXMLLevelTag

m_strXMLMsgTag

private String m_strXMLMsgTag
Constructor Detail

XMLDOMLoggerTarget

public XMLDOMLoggerTarget(Document xmlDOM)
Constructor.

Parameters:
xmlDOM - The XML DOM to write log entries to.
Method Detail

setXMLDOM

public void setXMLDOM(Document xmlDOM)
Set the XML DOM to write log entries to. If null, no logging to an XML DOM is performed.

Parameters:
xmlDOM - The new XML DOM.

getXMLDOM

public Document getXMLDOM()
Get the XML DOM that messages are currently being logged to.

Returns:
The XML DOM.

setXMLRootTag

public void setXMLRootTag(String strNew)
Set the XML root tag. All entries logged to the XML DOM will be nested inside this XML tag. If necessary, this tag will be created as a root node in the XML DOM.

Parameters:
strNew - The new XML root tag.

getXMLRootTag

public String getXMLRootTag()
Get the XML root tag.

Returns:
The XML root tag.

setXMLEntryTag

public void setXMLEntryTag(String strNew)
Set the XML tag used for "Entry" nodes. Each call to log() logs one entry.

Parameters:
strNew - The new XML Entry tag.

getXMLEntryTag

public String getXMLEntryTag()
Get the XML tag used for "Entry" nodes.

Returns:
The XML Entry tag.

setXMLDateTimeTag

public void setXMLDateTimeTag(String strNew)
Set the XML tag used for "DateTime" nodes.

Parameters:
strNew - The new XML DateTime tag.

getXMLDateTimeTag

public String getXMLDateTimeTag()
Get the XML tag used for "DateTime" nodes.

Returns:
The XML DateTime tag.

setXMLAppNameTag

public void setXMLAppNameTag(String strNew)
Set the XML tag used for "AppName" nodes.

Parameters:
strNew - The new XML AppName tag.

getXMLAppNameTag

public String getXMLAppNameTag()
Get the XML tag used for "AppName" nodes.

Returns:
The XML AppName tag.

setXMLAppVersionTag

public void setXMLAppVersionTag(String strNew)
Set the XML tag used for "AppVersion" nodes.

Parameters:
strNew - The new XML AppVersion tag.

getXMLAppVersionTag

public String getXMLAppVersionTag()
Get the XML tag used for "AppVersion" nodes.

Returns:
The XML AppVersion tag.

setXMLUsernameTag

public void setXMLUsernameTag(String strNew)
Set the XML tag used for "Username" nodes.

Parameters:
strNew - The new XML Username tag.

getXMLUsernameTag

public String getXMLUsernameTag()
Get the XML tag used for "Username" nodes.

Returns:
The XML Username tag.

setXMLThreadNameTag

public void setXMLThreadNameTag(String strNew)
Set the XML tag used for "ThreadName" nodes.

Parameters:
strNew - The new XML ThreadName tag.

getXMLThreadNameTag

public String getXMLThreadNameTag()
Get the XML tag used for "ThreadName" nodes.

Returns:
The XML ThreadName tag.

setXMLMillisecsTag

public void setXMLMillisecsTag(String strNew)
Set the XML tag used for "Millisecs" nodes.

Parameters:
strNew - The new XML Millisecs tag.

getXMLMillisecsTag

public String getXMLMillisecsTag()
Get the XML tag used for "Millisecs" nodes.

Returns:
The XML Millisecs tag.

setXMLUsedMemTag

public void setXMLUsedMemTag(String strNew)
Set the XML tag used for "UsedMem" nodes.

Parameters:
strNew - The new XML UsedMem tag.

getXMLUsedMemTag

public String getXMLUsedMemTag()
Get the XML tag used for "UsedMem" nodes.

Returns:
The XML UsedMem tag.

setXMLTotalMemTag

public void setXMLTotalMemTag(String strNew)
Set the XML tag used for "TotalMem" nodes.

Parameters:
strNew - The new XML TotalMem tag.

getXMLTotalMemTag

public String getXMLTotalMemTag()
Get the XML tag used for "TotalMem" nodes.

Returns:
The XML TotalMem tag.

setXMLLevelTag

public void setXMLLevelTag(String strNew)
Set the XML tag used for "Level" nodes.

Parameters:
strNew - The new XML Level tag.

getXMLLevelTag

public String getXMLLevelTag()
Get the XML tag used for "Level" nodes.

Returns:
The XML Level tag.

setXMLMsgTag

public void setXMLMsgTag(String strNew)
Set the XML tag used for "Msg" nodes.

Parameters:
strNew - The new XML Msg tag.

getXMLMsgTag

public String getXMLMsgTag()
Get the XML tag used for "Msg" nodes.

Returns:
The XML Msg tag.

log

public void log(Logger.Entry entry)
         throws TransformerException
Log the log entry to the XML DOM.

Specified by:
log in interface Logger.LoggerTarget
Parameters:
entry - The log entry to write to the log.
Throws:
TransformerException - When an error occurs adding to the XML.