log4j2.xml SMTP appender get .war context

136 Views Asked by At

We are sending alert emails out on the fatal log level. But we want to get the context name dynamically.

we are using the same war file for different context. We just rename the war file. So we need a generic solution in the .xml file. Best in the subject line.

1

There are 1 best solutions below

3
Vikas Sachdeva On

I think you can use Web Lookup feature provided by log4j2. It allows to access context path of the web application using ${web:contextPath} syntax. Your configuration file would look like -

<SMTP name="Mail" subject="FATAL - ${web:contextPath}" to="[email protected]" from="[email protected]"
          smtpHost="localhost" smtpPort="25" bufferSize="50">

Check more details of Web Lookup here