Top Description Fields Constructors Methods
org.apache.log.output.net

public Class SMTPOutputLogTarget

extends AbstractOutputTarget
Class Inheritance
Imports
java.util.Date, javax.mail.Address, .Message, .MessagingException, .Session, .Transport, javax.mail.internet.MimeMessage, org.apache.log.format.Formatter, org.apache.log.output.AbstractOutputTarget

Logkit output target that logs data via SMTP.
Authors
Avalon Development Team, Marcus Crafter
Since
1.1.0
Version
$Id: SMTPOutputLogTarget.java 506267 2007-02-12 04:06:06Z crossley $

Field Summary

Modifier and TypeField and Description
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 boolean
m_debug

Flag which controls whether debug is enabled for each message.

private final 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 final 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 final 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 final String
m_subject

Mail subject.

private final Address[]
m_toAddresses

Address to sent mail to.

Constructor Summary

AccessConstructor and Description
public
SMTPOutputLogTarget(final Session
mail session to be used
session
,
final Address[]
addresses logs should be sent to
toAddresses
,
final Address
address logs say they come from
fromAddress
,
final String
subject line logs should use
subject
,
final int
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.
maxMsgSize
,
final int
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.
maxDelayTime
,
final Formatter
log formatter to use
formatter
)

SMTPOutputLogTarget constructor.

public
SMTPOutputLogTarget(final Session
mail session to be used
session
,
final Address[]
addresses logs should be sent to
toAddresses
,
final Address
address logs say they come from
fromAddress
,
final String
subject line logs should use
subject
,
final int
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.
maxMsgSize
,
final Formatter
log formatter to use
formatter
)

SMTPOutputLogTarget constructor.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
private void
send()

Helper method to send the currently buffered message, if existing.

public void
setDebug(boolean
true to enable debugging, false to disable it
debug
)

Method to enable/disable debugging on the mail session.

protected synchronized void
write(final String
logging data to be written to target
data
)

Overrides org.apache.log.output.AbstractOutputTarget.write.

Method to write data to the log target.
Inherited from org.apache.log.output.AbstractOutputTarget:
doProcessEventgetFormatteropen

Field Detail

m_bufferback to summary
private StringBuffer m_buffer

Buffer containing current mail.

m_bufferTimeback to summary
private long m_bufferTime

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

m_debugback to summary
private boolean m_debug

Flag which controls whether debug is enabled for each message.

m_fromAddressback to summary
private final Address m_fromAddress

Address to mail is to be listed as sent from.

m_maxDelayTimeback to summary
private long m_maxDelayTime

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

m_maxMsgSizeback to summary
private final int m_maxMsgSize

Maximum size of mail, in units of log events.

m_messageback to summary
private Message m_message

Message to be sent.

m_msgSizeback to summary
private int m_msgSize

Current size of mail, in units of log events.

m_runnerback to summary
private Thread m_runner

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

m_sessionback to summary
private final Session m_session

Mail session.

m_shutdownback to summary
private boolean m_shutdown

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

m_subjectback to summary
private final String m_subject

Mail subject.

m_toAddressesback to summary
private final Address[] m_toAddresses

Address to sent mail to.

Constructor Detail

SMTPOutputLogTargetback to summary
public SMTPOutputLogTarget(final Session session, final Address[] toAddresses, final Address fromAddress, final String subject, final int maxMsgSize, final int maxDelayTime, final Formatter formatter)

SMTPOutputLogTarget constructor. It creates a logkit output target capable of logging to SMTP (ie. email, email gateway) targets.

Parameters
session:Session

mail session to be used

toAddresses:Address[]

addresses logs should be sent to

fromAddress:Address

address logs say they come from

subject:String

subject line logs should use

maxMsgSize:int

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:int

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:Formatter

log formatter to use

SMTPOutputLogTargetback to summary
public SMTPOutputLogTarget(final Session session, final Address[] toAddresses, final Address fromAddress, final String subject, final int maxMsgSize, final Formatter formatter)

SMTPOutputLogTarget constructor. It creates a logkit output target capable of logging to SMTP (ie. email, email gateway) targets.

Parameters
session:Session

mail session to be used

toAddresses:Address[]

addresses logs should be sent to

fromAddress:Address

address logs say they come from

subject:String

subject line logs should use

maxMsgSize:int

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:Formatter

log formatter to use

Method Detail

closeback to summary
public synchronized void close()

Overrides org.apache.log.output.AbstractOutputTarget.close.

Implements org.apache.log.util.Closeable.close.

Closes this log target. Sends currently buffered message, if existing.

sendback to summary
private void send()

Helper method to send the currently buffered message, if existing.

Only called when synchronized.

setDebugback to summary
public void setDebug(boolean debug)

Method to enable/disable debugging on the mail session.

Parameters
debug:boolean

true to enable debugging, false to disable it

writeback to summary
protected synchronized void write(final String data)

Overrides org.apache.log.output.AbstractOutputTarget.write.

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.

Parameters
data:String

logging data to be written to target