Remko,

Thanks for the answer. After looking into the sources some more I found
this:

   - SMTPAppender.append(), which seems to be the usual way of events being
   logged to this appender, sends the mail directly.
   - SMTPAppender.isFiltered(), which is an overriding of the usual logic
   "filtered => do not log", instead collects the events in the cyclic buffer.

To be honest, I am quite confused with this behavior. Could you perhaps
shed some light on it?

Regarding buffering mails and having 1 error not sent for a long time: I
see your point, there can be perhaps a timeout setting.

Rationale: way too often, errors are clustered together. More often than
not, my app will send a barrage of error mails, and then be quiet for a
while. Even a timeout of 1 second would decrease the mail traffic
substantially, without losing any information.

What is your opinion of my second problem, the app being blocked while the
mail is being sent?

Thanks!


Matej



On Thu, May 9, 2013 at 2:48 PM, Remko Popma <[email protected]> wrote:

> Matej,
>
> The docs may not be clear on this, but i believe this buffer is
> essentially for multithreaded access.
>
> Every event will be stored in the buffer, and then trigger a send(). You
> are right that sending happens in the calling thread. You could consider
> wrapping the smtp appender in an async appender.
>
> When a send happens, it will grab all events currently in the buffer and
> send them in a single email.
>
> I believe this is correct behavior. Otherwise you may only have one ERROR
> and the email never gets sent because the appender is waiting for 9 more
> events...
>
> Best regards,
> Remko
>
> Sent from my iPhone
>
> On 2013/05/09, at 21:32, Matej Vitásek <[email protected]> wrote:
>
> > Hi all,
> >
> > I'd like to report 2 problems I am encountering using the SMTPAppender. I
> > am using it* to send me mails whenever an ERROR is logged in a web
> > application.
> >
> > 1) Buffer size is ignored. Excerpt from my log4j2.xml:
> > <SMTP name="Mail" suppressExceptions="false" subject="Error Log"
> > to="..." from="..." smtpHost="smtp.gmail.com"
> > smtpPort="465" *bufferSize="10"* smtpProtocol="smtps" smtpUsername="..."
> > smtpPassword="...">
> > </SMTP>
> >
> > You will notice that the buffer size is 10. I'd expect to be getting
> > e-mails with 10 errors aggregated, but every e-mail always contains only
> > one error.
> >
> > Looking into SMTPAppender.append() I see a call to manager.sendEvents()
> > which does not aggregate the message - it just sends it. To me it seems
> > that append() should write into SMTPManager.buffer and send only if it's
> > full...
> >
> > 2) Sending the e-mail blocks the thread that logged the error. I don't
> know
> > how to "prove" this empirically, it's just a really clear subjective
> > feeling: whenever an error gets logged, the whole application just lags
> for
> > the time it takes to send the mail.
> >
> > Can I provide you some help in pinpointing this problem?
> >
> >
> > Overall: just ask if you need more information,
> >
> >
> > Thanks!
> >
> >
> > Matej
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to