Log4j Jakarta SMTP
Log4j Jakarta SMTP appender sends an e-mail when a specific logging event occurs, typically on errors or fatal errors.
Dependency
You need to have the org.apache.logging.log4j:log4j-jakarta-smtp
dependency in your classpath:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jakarta-smtp</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
SMTP Appender requires |
Configuration
The number of logging events delivered in an e-mail depend on the value of bufferSize
option.
The SMTP Appender keeps only the last bufferSize
logging events in its cyclic buffer.
This keeps memory requirements at a reasonable level while still delivering useful application context.
All events in the buffer are included in the email.
The buffer will contain the most recent events of level TRACE
to WARN
preceding the event that triggered the email.
The default behavior is to trigger sending an email whenever an ERROR
or higher severity event is logged and to format it as HTML.
The circumstances on when the email is sent can be controlled by setting one or more filters on the Appender.
As with other Appenders, the formatting can be controlled by specifying a Layout for the Appender.
Parameter | Type | Default | Description |
---|---|---|---|
|
|
The name of the Appender |
|
|
|
The email address of the sender |
|
|
|
The comma-separated list of reply-to email addresses |
|
|
|
The comma-separated list of recipient email addresses |
|
|
|
The comma-separated list of CC email addresses |
|
|
|
The comma-separated list of BCC email addresses |
|
|
|
The subject of the email message |
|
|
|
|
The maximum number of log events to be buffered for inclusion in the message |
|
|
|
The Layout to use to format the |
|
|
A Filter to determine if the event should be handled by this Appender.
More than one Filter may be used by using a |
|
|
|
|
When set to true enables session debugging on |
|
|
The SMTP hostname to send to. This parameter is required. |
|
|
|
The password required to authenticate against the SMTP server |
|
|
|
The SMTP port to send to |
|
|
|
|
The SMTP transport protocol; e.g., |
|
|
The username required to authenticate against the SMTP server |
|
|
|
|
Indicates if exceptions encountered while appending events to be internally logged and then ignored.
When set to |
|
|
Contains the configuration for the |
log4j.xml
demonstrating SMTP Appender usage<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp">
<Appenders>
<SMTP name="Mail"
subject="Error Log"
to="errors@logging.apache.org"
from="test@logging.apache.org"
smtpHost="localhost"
smtpPort="25"
bufferSize="50">
</SMTP>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Mail"/>
</Root>
</Loggers>
</Configuration>