atg.service.datacollection
Class FormattingLogger

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.datacollection.FormattingLogger
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, LogListener, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, DataCollector, DataListener, java.util.EventListener
Direct Known Subclasses:
FormattingConsoleLogger, FormattingFileLogger, FormattingSummaryLogger

public abstract class FormattingLogger
extends GenericService
implements DataCollector, LogListener

Base class for data collection loggers that emit plain text output. A FormattingLogger logs data items to a file with a user specfied format. Subclasses should override isValidFormatVariable() and appendField() to specify custom formatting for specialized data items. FormattingSummaryLogger is an example of this. Additionally, concrete subclasses need to initialize and cleanup the output writer. FormattingFileLogger is an example of this.

See Also:
FormatField, FormattingSummaryLogger

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
FormattingLogger()
           
 
Method Summary
 void addDataItem(java.lang.Object pDataItem)
          Handle data items for which we listen
 void appendField(FormatField pFormatField, java.lang.Object pDataItem, java.lang.StringBuffer pBuffer)
          Append the specified field of the specified object to the string buffer, applying appropriate formatting.
 void doStartService()
          This is called after the service has been created, added to the Registry, and configured.
 void doStopService()
          Flush our data buffers before we are stopped
 void flush()
          Flush out any data we may have.
 int getCount()
          Returns property Count
 java.lang.String getFieldDelimiter()
          Returns property FieldDelimiter
 FormatField[] getFormatFields()
          Returns property FormatFields
 java.lang.String getLineTerminator()
          Returns property LineTerminator
 boolean isSkipNullObject()
          Returns property SkipNullObject
 boolean isValidFormatField(FormatField pField)
          Is the specified format field valid for this logger?
 boolean isValidFormatVariable(java.lang.String pName)
          Determine if the specified name is the name of a valid format variable.
 void logEvent(LogEvent pLogEvent)
          Log an event.
 void sanitizeFormatFields()
          Filter out and log (if appropriate) any invalid format fields we have.
 void setFieldDelimiter(java.lang.String pFieldDelimiter)
          Sets property FieldDelimiter
 void setFormatFields(FormatField[] pFormatFields)
          Sets property FormatFields
 void setLineTerminator(java.lang.String pLineTerminator)
          Sets property LineTerminator
 void setSkipNullObject(boolean pSkipNullObject)
          Sets property SkipNullObject
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

FormattingLogger

public FormattingLogger()
Method Detail

getCount

public int getCount()
Returns property Count


setFormatFields

public void setFormatFields(FormatField[] pFormatFields)
Sets property FormatFields


getFormatFields

public FormatField[] getFormatFields()
Returns property FormatFields


setFieldDelimiter

public void setFieldDelimiter(java.lang.String pFieldDelimiter)
Sets property FieldDelimiter


getFieldDelimiter

public java.lang.String getFieldDelimiter()
Returns property FieldDelimiter


setLineTerminator

public void setLineTerminator(java.lang.String pLineTerminator)
Sets property LineTerminator


getLineTerminator

public java.lang.String getLineTerminator()
Returns property LineTerminator


setSkipNullObject

public void setSkipNullObject(boolean pSkipNullObject)
Sets property SkipNullObject


isSkipNullObject

public boolean isSkipNullObject()
Returns property SkipNullObject


sanitizeFormatFields

public void sanitizeFormatFields()
Filter out and log (if appropriate) any invalid format fields we have.


isValidFormatField

public boolean isValidFormatField(FormatField pField)
Is the specified format field valid for this logger?

Parameters:
pField - the format field to test
Returns:
true if field is valid, else false

isValidFormatVariable

public boolean isValidFormatVariable(java.lang.String pName)
Determine if the specified name is the name of a valid format variable. This is mostly for validating our properties file at startup. Note that this base class does not support any format variables. Subclasses that wish to support them should override this method.

Parameters:
pName - name to check
Returns:
true if name is valid, else false

logEvent

public void logEvent(LogEvent pLogEvent)
Log an event. This is a convenience method. We just pass this through to addDataItem.

Specified by:
logEvent in interface LogListener
Parameters:
pLogEvent - the log event

addDataItem

public void addDataItem(java.lang.Object pDataItem)
Handle data items for which we listen

Specified by:
addDataItem in interface DataListener
Parameters:
pDataItem - item to handle

doStartService

public void doStartService()
                    throws ServiceException
This is called after the service has been created, added to the Registry, and configured. This method should start any processes required to run the service.

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if an error occurred during the operation

doStopService

public void doStopService()
                   throws ServiceException
Flush our data buffers before we are stopped

Overrides:
doStopService in class GenericService
Throws:
ServiceException - if an error occurred

flush

public void flush()
Flush out any data we may have. Subclasses should override this if they have buffers that are periodically flushed.

Specified by:
flush in interface DataCollector

appendField

public void appendField(FormatField pFormatField,
                        java.lang.Object pDataItem,
                        java.lang.StringBuffer pBuffer)
Append the specified field of the specified object to the string buffer, applying appropriate formatting. Subclasses should override this method to format their own custom data items FormattingSummaryLogger is an example.

Parameters:
pFormatField - format field to use
pDataItem - bean whose property we are appending
pBuffer - buffer to which we append
See Also:
FormatField