Package org.apache.log.output.net
Class SMTPOutputLogTarget
- java.lang.Object
-
- org.apache.log.output.AbstractTarget
-
- org.apache.log.output.AbstractOutputTarget
-
- org.apache.log.output.net.SMTPOutputLogTarget
-
- All Implemented Interfaces:
ErrorAware,LogTarget,Closeable
public class SMTPOutputLogTarget extends AbstractOutputTarget
Logkit output target that logs data via SMTP.- Since:
- 1.1.0
- Version:
- $Id: SMTPOutputLogTarget.java 231246 2005-08-10 09:32:43 -0500 (Wed, 10 Aug 2005) leif $
- Author:
- Avalon Development Team, Marcus Crafter
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBufferm_bufferBuffer containing current mail.private longm_bufferTimeThe time that the first log entry in the current buffer arrived.private javax.mail.Addressm_fromAddressAddress to mail is to be listed as sent from.private longm_maxDelayTimeThe maximun delay that a message will be allowed to wait in the queue before being sent.private intm_maxMsgSizeMaximum size of mail, in units of log events.private javax.mail.Messagem_messageMessage to be sent.private intm_msgSizeCurrent size of mail, in units of log events.private java.lang.Threadm_runnerRunner thread which is responsible for sending batched log entries in the background.private javax.mail.Sessionm_sessionMail session.private booleanm_shutdownFlag which will be set in the close method when it is time to shutdown.private java.lang.Stringm_subjectMail subject.private javax.mail.Address[]m_toAddressesAddress to sent mail to.
-
Constructor Summary
Constructors Constructor Description SMTPOutputLogTarget(javax.mail.Session session, javax.mail.Address[] toAddresses, javax.mail.Address fromAddress, java.lang.String subject, int maxMsgSize, int maxDelayTime, Formatter formatter)SMTPOutputLogTarget constructor.SMTPOutputLogTarget(javax.mail.Session session, javax.mail.Address[] toAddresses, javax.mail.Address fromAddress, java.lang.String subject, int maxMsgSize, Formatter formatter)SMTPOutputLogTarget constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this log target.private voidsend()Helper method to send the currently buffered message, if existing.voidsetDebug(boolean flag)Method to enable/disable debugging on the mail session.protected voidwrite(java.lang.String data)Method to write data to the log target.-
Methods inherited from class org.apache.log.output.AbstractOutputTarget
doProcessEvent, getFormatter, open
-
Methods inherited from class org.apache.log.output.AbstractTarget
getErrorHandler, isOpen, processEvent, setErrorHandler
-
-
-
-
Field Detail
-
m_session
private final javax.mail.Session m_session
Mail session.
-
m_message
private javax.mail.Message m_message
Message to be sent.
-
m_toAddresses
private final javax.mail.Address[] m_toAddresses
Address to sent mail to.
-
m_fromAddress
private final javax.mail.Address m_fromAddress
Address to mail is to be listed as sent from.
-
m_subject
private final java.lang.String m_subject
Mail subject.
-
m_msgSize
private int m_msgSize
Current size of mail, in units of log events.
-
m_maxMsgSize
private final int m_maxMsgSize
Maximum size of mail, in units of log events.
-
m_buffer
private java.lang.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_maxDelayTime
private long m_maxDelayTime
The maximun delay that a message will be allowed to wait in the queue before being sent.
-
m_runner
private java.lang.Thread m_runner
Runner thread which is responsible for sending batched log entries in the background.
-
m_shutdown
private boolean m_shutdown
Flag which will be set in the close method when it is time to shutdown.
-
-
Constructor Detail
-
SMTPOutputLogTarget
public SMTPOutputLogTarget(javax.mail.Session session, javax.mail.Address[] toAddresses, javax.mail.Address fromAddress, java.lang.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 usedtoAddresses- addresses logs should be sent tofromAddress- address logs say they come fromsubject- subject line logs should usemaxMsgSize- 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(javax.mail.Session session, javax.mail.Address[] toAddresses, javax.mail.Address fromAddress, java.lang.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 usedtoAddresses- addresses logs should be sent tofromAddress- address logs say they come fromsubject- subject line logs should usemaxMsgSize- 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 Detail
-
write
protected void write(java.lang.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:
writein classAbstractOutputTarget- Parameters:
data- logging data to be written to target
-
close
public void close()
Closes this log target. Sends currently buffered message, if existing.- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractOutputTarget
-
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
-
send
private void send()
Helper method to send the currently buffered message, if existing.Only called when synchronized.
-
-