Is there a way to configure the SMTPAppender
in LogBack to meet the following criteria?
- Group all the exceptions into one message
- Only send the daily log report if exceptions occurred
- Send the report only once, grouped in one email, at a particular time of the day.
My current implementation is far from doing the above, but currently it sends 3 emails when an exception occurs - the exception message, the stacktrace, and a flush of the buffer.
<!-- Filter duplicate Log Messages - Very important for Email Reports -->
<turboFilter class="ch.qos.logback.classic.turbo.DuplicateMessageFilter">
<AllowedRepetitions>1</AllowedRepetitions>
<CacheSize>1000</CacheSize>
</turboFilter>
<!--
############################################################
BASIC APPENDER
############################################################
-->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{HH:mm:ss.SSS} %-55(%X{user} %level [%thread] %logger{20}) - %msg%n</pattern>
</encoder>
</appender>
<!--
############################################################
EMAIL APPENDER
############################################################
-->
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<appender name="Email" class="ch.qos.logback.classic.net.SMTPAppender">
<smtpHost>SERVER</smtpHost>
<smtpPort>PORT</smtpPort>
<asynchronousSending>false</asynchronousSending>
<from>SENDER</from>
<to>RECIPIENT</to>
<subject>SUBJECT</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS} %-55(%X{user} %level [%thread] %logger{20}) - %msg%n</pattern>
</layout>
</appender>
<!--
############################################################
OTHER
############################################################
-->
<root level="INFO">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFile"/>
<appender-ref ref="Email"/>
</root>
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type lloyds.utils.ScheduledSMTPAppender
followed byjava.lang.InstantiationException
due toch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter
. Any thoughts? – Unwilled