Skip to content

eureka-bpo/gmail-log4j2-appender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven

GMail Appender for Log4j2

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.

Simplest example

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" />

Attributes description

  • serviceAccountKey - absolute path to key file of service account
  • delegate - user account, which delegates sending emails to service account
    Note: on step 5 scope https://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

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>

System requirements

Requires Java >= 11 and Log4j >= 2.11.2