With help of this appender user can receive notifications about errors direct on GMail.
Usage of GMail Appender is possible after Google OAuth2 settings are set.
The simplest appender configuration for usage with log4j2:
<GMail name="GMailLogger"
serviceAccountKey="/path/to/key/file.json"
delegate="example@gmail.com"
subject="Subject of emails"
recipients="recipient@example.com" />
- serviceAccountKey - absolute path to key file of service account
- delegate - user account, which delegates sending emails to service account
Note: on step 5 scopehttps://www.googleapis.com/auth/gmail.send
should be granted - subject - subject of sending emails
- recipients - list of recipients of sending emails. Must follow RFC822 syntax
Full example of log4j2 configuration with GMail appender:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[Log4j]%d{HH:mm:ss.SSS} %-5level - %msg%n" />
</Console>
<GMail name="GMailLogger"
serviceAccountKey="/path/to/key/file.json"
delegate="example@gmail.com"
subject="Subject of emails"
recipients="recipient@example.com">
</GMail>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="GMailLogger" level="error" />
</Root>
</Loggers>
</Configuration>
Requires Java >= 11 and Log4j >= 2.11.2