Home » Java » java – Limit Logback Email to Enrivonment-Exceptionshub

java – Limit Logback Email to Enrivonment-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Although the Java project I’m working with contains different jconfig XML files per environment, it has one logback XML file for the entire project.

Inside, there is an SMTPAppender like:

    <appender name="ERROR_EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <SMTPHost>${logs.smtp.host}</SMTPHost>
        <To>@abc.com</To>
        <From>[email protected]</From>
        <Subject>[Error occurred in ${environment}</Subject>
    </appender>

As you see, access to the environment variable is available so can this be utilized to only send this ERROR_EMAIL in certain environments?

Thank you very much for your time!

How to&Answers: