Log4j email appender configuration:
log4j.appender.myMail=org.apache.log4j.net.SMTPAppender
log4j.appender.myMail.threshold=WARN
log4j.appender.myMail.SMTPHost=smtp.163.com
log4j.appender.myMail.BufferSize=16
log4j.appender.myMail.SMTPUsername=username
log4j.appender.myMail.SMTPPassword=password
log4j.appender.myMail.subject=Log4j Email Notification Test - ${app.environment}
[email protected]
[email protected]
log4j.appender.myMail.layout=org.apache.log4j.PatternLayout
log4j.appender.myMail.layout.ConversionPattern=[Error Message:]%d{ISO8601} %5p [%t] (%F:%L) – %m%n
=================================================================
log4j.appender.myMail.subject=Log4j Email Notification Test - ${app.environment}
There is a way to eliminate this difference and maintain a single log4j properties file for all environments. The solution is to use substitution variables in the form ${variable-name}. The java system property with the same name will have its value substituted for this text. For the above example, the parametrized email subject would become
log4j.appender.email.Subject=Log4j Email Notification Test - ${app.environment}
The system property app.environment can be initialized at application startup on the command-line or within the application server.
Sample for setting system property when start tomcat :
create a new file(Linux):
#!/bin/bash
export JAVA_OPTS=-Dapps.environment=development
bin/startup.sh