Skip to content
Log4j2 Elasticsearch Appender plugins
Java
Branch: master
Clone or download

README.md

log4j2-elasticsearch overview

Build Status Maven Central codecov contributions welcome

This is a parent project for log4j2 appender plugins capable of pushing logs in batches to Elasticsearch clusters.

Project consists of:

  • log4j-elasticsearch-core - skeleton provider for conrete implementations
  • log4j2-elasticsearch-hc - optimized Apache Async HTTP client compatible with Elasticsearch 2.x, 5.x, 6.x and 7.x clusters
  • log4j-elasticsearch-jest - Jest HTTP Client compatible with Elasticsearch 2.x, 5.x, 6.x and 7.x clusters
  • log4j-elasticsearch2-bulkprocessor - TCP client compatible with 2.x clusters
  • log4j-elasticsearch5-bulkprocessor - TCP client compatible with 5.x and 6.x clusters
  • log4j-elasticsearch6-bulkprocessor - TCP client compatible with 6.x clusters

Features

  • Asynchronous log delivery
  • Batch size and flush interval configuration
  • Failover (redirect failed batch to alternative target)
  • JSON message format (user-provided or JacksonJsonLayout by default since 1.3 or Log4j2 JsonLayout)
  • (since 1.1) Index rollover (hourly, daily, etc.)
  • (1.1) Index template configuration
  • (1.2) Basic Authentication (XPack Security and Shield support)
  • (1.2) HTTPS support (XPack Security and Shield - visit submodules for compatibility matrix)
  • (1.3) Buffer object pool (memory allocation reduced by ~80%)
  • (1.3) Buffered Jest HTTP client
  • (1.3) Fully configurable JSON output using JacksonJsonLayout
  • (1.4 - H2 2019) Reliable, file-based failover/retry
  • (1.4) log4j2-elasticsearch-hc module - optimized async HTTP client

Usage

  1. Add this snippet to your pom.xml file:
<dependency>
    <groupId>org.appenders.log4j</groupId>
    <artifactId>log4j2-elasticsearch-jest</artifactId>
    <version>1.3.5</version>
</dependency>

(ensure that Log4j2 and Jackson FasterXML jars are added as well - see Dependencies section below)

  1. Add this snippet to log4j2.xml configuration:
<Appenders>
    <Elasticsearch name="elasticsearchAsyncBatch">
        <IndexName indexName="log4j2" />
        <AsyncBatchDelivery>
            <IndexTemplate name="log4j2" path="classpath:indexTemplate.json" />
            <JestHttp serverUris="http://localhost:9200" />
        </AsyncBatchDelivery>
    </Elasticsearch>
</Appenders>

or log4j2.properties (see example)

or configure programmatically

  1. Start logging directly to Elasticsearch!
Logger log = LogManager.getLogger("Logger that references elasticsearchAsyncBatch")
log.info("Hello, World!");

Dependencies

Be aware that Jackson FasterXML jars that has to be provided by user for this library to work in default mode. Please visit mvnrepository for an overview of provided and compile dependencies

Released to Sonatype OSS repos

Visit submodules' documentation or mvnrepository for XML snippets.

You can’t perform that action at this time.