atg.nucleus.logging
Class EmailLogger

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.logging.EmailLogger
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, LogListener, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, Schedulable, java.util.EventListener

public class EmailLogger
extends GenericService
implements LogListener, Schedulable

This log listener writes the logged events as an email message. One can optionally queue up received LogEvents and process them into a single batched email messages. Set the logEventThreshold property to the number of messages to queue. One can also make sure that any queued email messages are delivered on a regular schedule. This class supports the Schedulable interface and can very easily be managed to send out any pending LogEvents every N seconds.

See Also:
Schedulable

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
EmailLogger()
          Constructs an EmailLogger.
 
Method Summary
 void addEmailListener(EmailListener pListener)
          Adds a listener to the list of email listeners
 void doStartService()
          Perfrom any necessary initializations to startup service.
If a schedule is provided, then it is started.
 void doStopService()
          Performs tasks required to shutdown service.
 void flushLogEventQueue()
          Sends all the queued LogEvents and sends them as one email message
 java.lang.String getDefaultBody()
          Returns the default message body, that should be prepended to all emails
 java.lang.String[] getDefaultExtraHeaders()
          Returns the default list of extra headers that should be used in the email (e.g.
 java.lang.String getDefaultFrom()
          Returns the default sender (From:) field.
 java.lang.String[] getDefaultRecipients()
          Returns the default list of Recipients that should receive email
 java.lang.String getDefaultSubject()
          Returns the default subject field.
 int getEmailListenerCount()
          Returns the number of email listeners
 int getLogEventThreshold()
          Returns the number of LogEvents that should be queued before an email is sent
 Schedule getSchedule()
           
 Scheduler getScheduler()
           
 void logEvent(LogEvent pLogEvent)
          Sends the given log event out via email
 void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)
          Flushes the avaliable queue entries
 void removeEmailListener(EmailListener pListener)
          Removes a listener from the list of email listeners
 void setDefaultBody(java.lang.String pBody)
          Sets the default message body, that should be prepended to all emails
 void setDefaultExtraHeaders(java.lang.String[] pExtraHeaders)
          Sets the default list of extra headers that should be used in the email (e.g.
 void setDefaultFrom(java.lang.String pFrom)
          Sets the default sender (From:) field.
 void setDefaultRecipients(java.lang.String[] pRecipients)
          Sets the default list of Recipients that should receive email
 void setDefaultSubject(java.lang.String pSubject)
          Sets the default subject field.
 void setLogEventThreshold(int pNum)
          Sets the number of LogEvents that should be queued before an email is sent
 void setSchedule(Schedule pSchedule)
           
 void setScheduler(Scheduler pScheduler)
           
protected  void startScheduledJob()
          Starts the EmailLogger's job which flushes the queue entries periodically
protected  void stopScheduledJob()
          Stops the EmailLogger's job which flushes the queue entries periodically
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, 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

EmailLogger

public EmailLogger()
Constructs an EmailLogger.

Method Detail

getScheduler

public Scheduler getScheduler()

setScheduler

public void setScheduler(Scheduler pScheduler)

getSchedule

public Schedule getSchedule()

setSchedule

public void setSchedule(Schedule pSchedule)

getDefaultRecipients

public java.lang.String[] getDefaultRecipients()
Returns the default list of Recipients that should receive email


setDefaultRecipients

public void setDefaultRecipients(java.lang.String[] pRecipients)
Sets the default list of Recipients that should receive email


getDefaultFrom

public java.lang.String getDefaultFrom()
Returns the default sender (From:) field.


setDefaultFrom

public void setDefaultFrom(java.lang.String pFrom)
Sets the default sender (From:) field.


getDefaultSubject

public java.lang.String getDefaultSubject()
Returns the default subject field.


setDefaultSubject

public void setDefaultSubject(java.lang.String pSubject)
Sets the default subject field.


getDefaultExtraHeaders

public java.lang.String[] getDefaultExtraHeaders()
Returns the default list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")


setDefaultExtraHeaders

public void setDefaultExtraHeaders(java.lang.String[] pExtraHeaders)
Sets the default list of extra headers that should be used in the email (e.g. "X-URL: http://foo.bar.com/")


getDefaultBody

public java.lang.String getDefaultBody()
Returns the default message body, that should be prepended to all emails


setDefaultBody

public void setDefaultBody(java.lang.String pBody)
Sets the default message body, that should be prepended to all emails


getLogEventThreshold

public int getLogEventThreshold()
Returns the number of LogEvents that should be queued before an email is sent


setLogEventThreshold

public void setLogEventThreshold(int pNum)
Sets the number of LogEvents that should be queued before an email is sent


addEmailListener

public void addEmailListener(EmailListener pListener)
Adds a listener to the list of email listeners


removeEmailListener

public void removeEmailListener(EmailListener pListener)
Removes a listener from the list of email listeners


getEmailListenerCount

public int getEmailListenerCount()
Returns the number of email listeners


doStartService

public void doStartService()
                    throws ServiceException
Perfrom any necessary initializations to startup service.
If a schedule is provided, then it is started.

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

doStopService

public void doStopService()
                   throws ServiceException
Performs tasks required to shutdown service.

Overrides:
doStopService in class GenericService
Throws:
ServiceException - if the Service had a problem shutting down

startScheduledJob

protected void startScheduledJob()
Starts the EmailLogger's job which flushes the queue entries periodically


stopScheduledJob

protected void stopScheduledJob()
Stops the EmailLogger's job which flushes the queue entries periodically


performScheduledTask

public void performScheduledTask(Scheduler pScheduler,
                                 ScheduledJob pJob)
Flushes the avaliable queue entries

Specified by:
performScheduledTask in interface Schedulable
Parameters:
pScheduler - calling the job
pJob - the ScheduledJob

flushLogEventQueue

public void flushLogEventQueue()
Sends all the queued LogEvents and sends them as one email message


logEvent

public void logEvent(LogEvent pLogEvent)
Sends the given log event out via email

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