My logback has two appenders a console and an email appender, which extends from my custom SMPTAppender
... My logger logger.error("My error");
triggers an email to be sent after x - minutes in my custom SMTPAppender, the problem is that, the scheduler doesn't wait for the delay, as two are initialized.
This happens twice:
Attaching appender named [EMAIL] to Logger[ROOT]
That's why IMO also two schedulers are created (start
method is invoked twice)
Logback.xml (Where the problem should be):
<configuration debug="true">
Logging per console and per email
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
sets the format of the output
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="EMAIL" class="com.konverto.phonebillasaj.appenders.ScheduledSMTPAppender">
<subject>TESTING: %logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout" />
<smtpHost>smtp.xxx.net</smtpHost>
<smtpPort>587</smtpPort>
<STARTTLS>true</STARTTLS>
<username>xxxx@xxx.net</username>
<password>xxxx</password>
<to>xxx@xxx.net</to>
<from>xxx@xxx.net</from>
<maxMessages>10</maxMessages>
for testing , comment in production, default 256
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
Send just one log entry per email, ready for a lot of emails if you put one.
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
for testing , comment in production, default asynchronousSending = true
<asynchronousSending>false</asynchronousSending>
</appender>
<logger name="com.konverto.phonebillasaj" level="error" additivity="false">
<appender-ref ref="EMAIL"/>
<appender-ref ref="CONSOLE" />
</logger>
<root level="error">
<appender-ref ref="EMAIL" />
<appender-ref ref="CONSOLE" />
</root>