Class DynamicContextDataProvider

java.lang.Object
org.elasticsearch.common.logging.DynamicContextDataProvider
All Implemented Interfaces:
org.apache.logging.log4j.core.util.ContextDataProvider

public class DynamicContextDataProvider extends Object implements org.apache.logging.log4j.core.util.ContextDataProvider
An implementation of log4j2's ContextDataProvider that can be configured at runtime (after being loaded by log4j's init mechanism). A ContextDataProvider can enrich a logging event with additional "context data" (a string-to-string map of additional fields). Elasticsearch (via ECSJsonLayout logs these additional fields in the json formatted log. Log4j loads ContextDataProvider instances using SPI during logging initialisation. In Elasticsearch this initialisation happens early in the bootstrap process, before Elasticsearch modules and plugins are loaded. Thus, it is not possible for an Elasticsearch plugin to register a ContextDataProvider service with log4j. Instead, Elasticsearch allows plugins to implement the LoggingDataProvider which is loaded via Elasticsearch's SPI implementation (as part of plugin loading). This DynamicContextDataProvider class is the bridge between the Elasticsearch and log4j systems.
  • Constructor Details

    • DynamicContextDataProvider

      public DynamicContextDataProvider()
  • Method Details

    • setDataProviders

      public static void setDataProviders(List<? extends LoggingDataProvider> dataProviders)
    • supplyContextData

      public Map<String,String> supplyContextData()
      Specified by:
      supplyContextData in interface org.apache.logging.log4j.core.util.ContextDataProvider