[logback-user] SMTPAppender mail not sent (logback 1.0.0, JDK 1.5)

Thorbjørn Ravn Andersen thunderaxiom at hotmail.com
Tue Jan 31 13:35:11 CET 2012


Hi.

Just ran into this bug as well (Java 1.5, logback 1.0.0, Windows 7).  

It appears that the code in SMTPAppenderBase

      if (eventEvaluator.evaluate(eventObject)) {
        // perform actual sending asynchronously
        SenderRunnable senderRunnable = new SenderRunnable(new CyclicBuffer<E>(cb), eventObject);
        context.getExecutorService().execute(senderRunnable);
      }

is properly executed, but as noted the SenderRunable.run() method is not invoked (which I have determined by having a break point).

The ThreadPoolExecutor.execute() method (under Oracle Java 1.5) executes:

   public void execute(Runnable command) {
        if (command == null)
            throw new NullPointerException();
        for (;;) {
            if (runState != RUNNING) {
                reject(command);
                return;
            }
            if (poolSize < corePoolSize && addIfUnderCorePoolSize(command))
                return;
            if (workQueue.offer(command))
                return;

and returns (and the SenderRunnable was added to workQueue).  

There is, however, a potential problem of mails being lost.  In the code causing me to investigate this, the "log.error("....", e)" is immediately followed by a System.exit().  In other words - I will most likely loose most of the mails generated by this code as the async process is slower than the System.exit().

Is there any way of guaranteeing that all mail has been transported before stopping the program?

If not, can I have a flag simply saying "do not run async, run in process" which invokes senderRunnable.run() directly instead of delegating to an executor?

(also a way of telling the operator that mail has been sent would be nice.  It can be as simple as a print statement, similar to

	@Override
	protected void sendBuffer(
			ch.qos.logback.core.helpers.CyclicBuffer<ILoggingEvent> cb,
			ILoggingEvent lastEventObject) {

		System.out.println("[" + new java.util.Date() + " "
				+ this.getClass().getSimpleName()
				+ " sending e-mail notification with " + cb.length()
				+ " events]");

		super.sendBuffer(cb, lastEventObject);
	};
)

Thanks

/Thorbjørn

-----Original Message-----
From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On Behalf Of ceki
Sent: 29. januar 2012 18:49
To: logback users list
Subject: Re: [logback-user] SMTPAppender mail not sent (logback 1.0.0, JDK 1.5)

Hi,

I intend to look into this tomorrow morning.

--
Ceki
http://twitter.com/#!/ceki

On 29.01.2012 17:36, samyem wrote:
>
>
> I am facing the exact same issue. The upgrade stopped sending emails 
> for me as well. For some reason, the Runnable class SMTPAppender's 
> "run" method never gets executed in this new version. Anyone else having this issue?
>
> Thanks,
>
>
> Louis-Félix wrote:
>>
>> Hi,
>>
>> I upgraded to logback 1.0.0 in a web application (tomcat 5, JDK 1.5), 
>> and the ERROR email are not sent anymore from the SMTPAppender.
>> When I rollback my logback-core and logback-classic JARs to version 
>> 0.9.30, it's working again.
>>
>> I have a simple config:
>>
>>      <appender name="courriel"
>> class="ch.qos.logback.classic.net.SMTPAppender">
>>          <smtpHost>smtp.xxx.xx.xx</smtpHost>
>>          <to>xxx at xxx.xx.xx</to>
>>          <from>no-reply.ti at xxx.xx.xx</from>
>>          <subject>Test</subject>
>>          <cyclicBufferTracker
>> class="ch.qos.logback.core.spi.CyclicBufferTrackerImpl">
>>              <bufferSize>25</bufferSize>
>>          </cyclicBufferTracker>
>>          <layout class="ch.qos.logback.classic.html.HTMLLayout">
>>              <pattern>%date%level%thread%logger%line%message</pattern>
>>          </layout>
>>      </appender>
>>
>> I am using logback 1.0.0 with no problem in an other project (with 
>> JDK 1.6).
>> Is there any known compatibility problem between logback 1.0.0 and 
>> JDK 1.5?
>>
>> Thanks,
>> Louis-Félix
>>

_______________________________________________
Logback-user mailing list
Logback-user at qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list