1

log4j 2.0-beta9 を使用しています。SMTP アペンダーについて質問があります。サブジェクト、from および to の値をプロパティから構成する必要があります。私は MapMessage をログに記録しています。私の設定は以下のとおりです -

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="DEBUG">

    <appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d [%t] %-5p %c  - %m%n"/>
        </Console>

        <SMTP name="Mail" subject="Error Log for ${env:HOSTNAME}" to="${sys:mail.to}" from="${sys:mail.from}"
              smtpHost="${sys:mail.host}" smtpPort="${sys:mail.port}" smtpDebug="true" bufferSize="1">
            <PatternLayout>
                <pattern>%d [%t] %-5p %c - %m%n</pattern>
            </PatternLayout>
        </SMTP>

        <Async name="AsyncMail">
            <appender-ref ref="Mail" />
        </Async>
    </appenders>

    <loggers>
        <root level="info">
            <appender-ref ref="Console"/>
            <appender-ref ref="AsyncMail">
                <MapFilter onMatch="ACCEPT" onMismatch="DENY">
                    <KeyValuePair key="throwable.class" value="java.lang.RuntimeException" />
                </MapFilter>
            </appender-ref>
        </root>
    </loggers>
</configuration>


// Java Code to log the msg
Throwable throwable; // this is the exception that is thrown by the app.
MapMessage message = new MapMessage();
message.put("throwable.message", throwable.getMessage());
message.put("throwable.class", throwable.getClass().getName());
message.put("throwable.stacktrace", ExceptionUtils.getStackTrace(throwable)); // ExceptionUtils from apache-commons
LOGGER.error(message, throwable); // org.apache.logging.log4j.Logger

問題は、これらの値が動的に置き換えられないことです。これを行う方法はありますか?

前もって感謝します。

4

1 に答える 1