title: How to index logs from java program (log4j2) into elasticsearch
body: <p>How can I index logs directly from log4j2 into elasticsearch index?</p>
  
  <p>Main.class:</p>
  
  <pre><code>import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  public class Main {
      private static final Logger logger = LogManager.getLogger(Main.class);
      public static void main(String... args) {
          logger.info("This is an info message.");
          logger.error("This is an error message");
      }
  }
  </code></pre>
  
  <p>log4j2.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="warn"&gt;
      &lt;Appenders&gt;
          &lt;Console name="STDOUT" target="SYSTEM_OUT"&gt;
              &lt;PatternLayout pattern="%m%n"/&gt;
          &lt;/Console&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Root level="trace"&gt;
              &lt;AppenderRef ref="STDOUT" level="trace"/&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>I want to know if there is a way to inject logs directly into elasticsearch, by adding dependency and appenders to logger.</p>