org.apache.log.output.net

Class SMTPOutputLogTarget

Implemented Interfaces:
Closeable, ErrorAware, LogTarget

public class SMTPOutputLogTarget
extends AbstractOutputTarget

Logkit output target that logs data via SMTP.
Version:
$Id: SMTPOutputLogTarget.java 231246 2005-08-10 09:32:43 -0500 (Wed, 10 Aug 2005) leif $
Authors:
Avalon Development Team
Marcus Crafter
Since:
1.1.0

Field Summary

private StringBuffer
m_buffer
Buffer containing current mail.
private long
m_bufferTime
The time that the first log entry in the current buffer arrived.
private Address
m_fromAddress
Address to mail is to be listed as sent from.
private long
m_maxDelayTime
The maximun delay that a message will be allowed to wait in the queue before being sent.
private int
m_maxMsgSize
Maximum size of mail, in units of log events.
private Message
m_message
Message to be sent.
private int
m_msgSize
Current size of mail, in units of log events.
private Thread
m_runner
Runner thread which is responsible for sending batched log entries in the background.
private Session
m_session
Mail session.
private boolean
m_shutdown
Flag which will be set in the close method when it is time to shutdown.
private String
m_subject
Mail subject.
private Address[]
m_toAddresses
Address to sent mail to.

Fields inherited from class org.apache.log.output.AbstractOutputTarget

m_formatter

Fields inherited from class org.apache.log.output.AbstractTarget

DEFAULT_ERROR_HANDLER, m_errorHandler, m_isOpen

Constructor Summary

SMTPOutputLogTarget(Session session, Address[] toAddresses, Address fromAddress, String subject, int maxMsgSize, int maxDelayTime, Formatter formatter)
SMTPOutputLogTarget constructor.
SMTPOutputLogTarget(Session session, Address[] toAddresses, Address fromAddress, String subject, int maxMsgSize, Formatter formatter)
SMTPOutputLogTarget constructor.

Method Summary

void
close()
Closes this log target.
private void
send()
Helper method to send the currently buffered message, if existing.
void
setDebug(boolean flag)
Method to enable/disable debugging on the mail session.
protected void
write(String data)
Method to write data to the log target.

Methods inherited from class org.apache.log.output.AbstractOutputTarget

close, doProcessEvent, format, getFormatter, getHead, getTail, open, write, writeHead, writeTail

Methods inherited from class org.apache.log.output.AbstractTarget

close, doProcessEvent, getErrorHandler, isOpen, open, processEvent, setErrorHandler

Field Details

m_buffer

private StringBuffer m_buffer
Buffer containing current mail.

m_bufferTime

private long m_bufferTime
The time that the first log entry in the current buffer arrived.

m_fromAddress

private final Address m_fromAddress
Address to mail is to be listed as sent from.

m_maxDelayTime

private long m_maxDelayTime
The maximun delay that a message will be allowed to wait in the queue before being sent.

m_maxMsgSize

private final int m_maxMsgSize
Maximum size of mail, in units of log events.

m_message

private Message m_message
Message to be sent.

m_msgSize

private int m_msgSize
Current size of mail, in units of log events.

m_runner

private Thread m_runner
Runner thread which is responsible for sending batched log entries in the background.

m_session

private final Session m_session
Mail session.

m_shutdown

private boolean m_shutdown
Flag which will be set in the close method when it is time to shutdown.

m_subject

private final String m_subject
Mail subject.

m_toAddresses

private final Address[] m_toAddresses
Address to sent mail to.

Constructor Details

SMTPOutputLogTarget

public SMTPOutputLogTarget(Session session,
                           Address[] toAddresses,
                           Address fromAddress,
                           String subject,
                           int maxMsgSize,
                           int maxDelayTime,
                           Formatter formatter)
SMTPOutputLogTarget constructor. It creates a logkit output target capable of logging to SMTP (ie. email, email gateway) targets.
Parameters:
session - mail session to be used
toAddresses - addresses logs should be sent to
fromAddress - address logs say they come from
subject - subject line logs should use
maxMsgSize - maximum size of any log mail, in units of log events. If this is greater than one but maxDelayTime is 0 then log events may stay queued for a long period of time if less than the specified number of messages are logged. Any unset messages will be sent when the target is closed.
maxDelayTime - specifies the longest delay in seconds that a log entry will be queued before being sent. Setting this to a value larger than 0 will cause a background thread to be used to queue up and send messages. Ignored if maxMsgSize is 1 or less.
formatter - log formatter to use

SMTPOutputLogTarget

public SMTPOutputLogTarget(Session session,
                           Address[] toAddresses,
                           Address fromAddress,
                           String subject,
                           int maxMsgSize,
                           Formatter formatter)
SMTPOutputLogTarget constructor. It creates a logkit output target capable of logging to SMTP (ie. email, email gateway) targets.
Parameters:
session - mail session to be used
toAddresses - addresses logs should be sent to
fromAddress - address logs say they come from
subject - subject line logs should use
maxMsgSize - maximum size of any log mail, in units of log events. Log events may stay queued for a long period of time if less than the specified number of messages are logged. Any unset messages will be sent when the target is closed.
formatter - log formatter to use

Method Details

close

public void close()
Closes this log target. Sends currently buffered message, if existing.
Specified by:
close in interface Closeable
Overrides:
close in interface AbstractOutputTarget

send

private void send()
Helper method to send the currently buffered message, if existing.

Only called when synchronized.


setDebug

public void setDebug(boolean flag)
Method to enable/disable debugging on the mail session.
Parameters:
flag - true to enable debugging, false to disable it

write

protected void write(String data)
Method to write data to the log target. Logging data is stored in an internal buffer until the size limit is reached. When this happens the data is sent to the SMTP target, and the buffer is reset for subsequent events.
Overrides:
write in interface AbstractOutputTarget
Parameters:
data - logging data to be written to target