Enabling Email Logging from Log4j2
The following sample configuration will enable email logging of ERROR level log messages in your application. When an error is encountered in startup and during operations of the product any ERROR message displayed on the console log file will be emailed to an Administrator's email account or email group.
Note: The change outlined below will make manual changes to a configuration file. Execution of initialSetup may overwrite these changes unless template overrides are used. See initialSetup – Maintain Configuration Settings and Implementing Custom Templates for details. Please ensure you make adequate backups to preserve this change. Refer to https://logging.apache.org/log4j/2.x/manual/appenders.html#SMTPAppender for details of the appender.
The following changes are required to enable this.
1. Open the log4j2.properties in the relevant $SPLEBASE/etc/conf subdirectory:
Web Application Server – log4j2.properties – Product Logging Configuration
Business Application Server - log4j2.properties – Product Logging Configuration
2. Add the following lines to the file:
### E1 is an EmailAppender
log4j2.appender.E1 = org.apache.log4j2.net.SMTPAppender
log4j2.appender.E1.Threshold = ERROR
log4j2.appender.E1.layout = org.apache.log4j2.PatternLayout log4j2.appender.E1.layout.ConversionPattern = %d{ISO8601} [%t] %-5p %c %x - %m%n
log4j2.appender.E1.From = <from>
log4j2.appender.E1.SMTPHost = <SMTPHost>
log4j2.appender.E1.Subject = <subject>
log4j2.appender.E1.To = <to>
###
### The following settings are optional
###
log4j2.appender.E1.SMTPUsername = <SMTPUsername>
log4j2.appender.E1.SMTPPassword = <SMTPPassword>
log4j2.appender.E1.CC = <cc>
log4j2.appender.E1.BCC = <bcc>
 
Parameter
Field From Example
Usage
From
<from>
Email address for emails.
To
<to>
Email address/group to send emails to.
CC
<cc>
Email address/group to send courtesy copy of emails to.
BCC
<bcc>
Email address/group to send a courtesy copy of emails to.
SMTPHost
<SMTPHost>
Host Name of SMTP Server.
SMTPUsername
<SMTPUsername>
User for the SMTP server (if supported).
SMTPPassword
<SMTPPassword>
Password for the SMTP Server (if supported).
Subject
<subject>
Subject for email message.
3. Modify the following lines in the log4j.properties file:
## System-wide settings
# set log levels - for more verbose logging change 'info' to 'debug' ###
log4j2.rootCategory=info, A1, F1, E1
4. Execute the initialSetup – Maintain Configuration Settings utility, with the –w option, to reflect the changes in the WAR/EAR file.
To deploy the application refer to the Web Application Server Deployment Process or Web Application Server Deployment Process.