title: How to make fluent-logger-java work with logback appender in springboot
body: <p>I am trying to integrate fluent-logger-java with a springboot project with a logback appender. And I am able to send data to a fluentd aggregator with the sample code given in <a href="https://github.com/fluent/fluent-logger-java" rel="nofollow noreferrer">https://github.com/fluent/fluent-logger-java</a></p>
  
  <p>But when added as a logback appender, it throws NullPointerException.
  I have tried to use logback-more-appenders from <a href="https://mvnrepository.com/artifact/com.sndyuk/logback-more-appenders/1.4.3" rel="nofollow noreferrer">https://mvnrepository.com/artifact/com.sndyuk/logback-more-appenders/1.4.3</a>.
  But it is not sending any data from the application.</p>
  
  <p>To reproduce the issue, generate a simple web project from <a href="https://start.spring.io/" rel="nofollow noreferrer">https://start.spring.io/</a> with defaults.</p>
  
  <p>Add src\main\java\com\example\demo\FluentLogbackAppender.java to the project</p>
  
  <pre><code>package com.example.demo;
  import java.util.HashMap;
  import java.util.Map;
  import org.fluentd.logger.FluentLogger;
  import ch.qos.logback.classic.spi.ILoggingEvent;
  import ch.qos.logback.core.UnsynchronizedAppenderBase;
  
  public class FluentLogbackAppender extends UnsynchronizedAppenderBase&lt;ILoggingEvent&gt; {
      private FluentLogger fluentLogger;
      private String label = "test";
  
      @Override
      public void start() {
          super.start();
          this.fluentLogger = FluentLogger.getLogger(label, "localhost", 24224);
          Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
          data.put("msg", "Starting App");
          fluentLogger.log(label, data);
      }
  
      @Override
      protected void append(ILoggingEvent rawData) {
          String msg = rawData.toString();
          Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;(1);
          data.put("msg", msg);
          fluentLogger.log(label, data);
      }
  
      @Override
      public void stop() {
          super.stop();
          fluentLogger.close();
      }
  }
  </code></pre>
  
  <p>Add src\main\resources\logback.xml to the project</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE logback&gt;
  &lt;configuration&gt;
      &lt;include resource="org/springframework/boot/logging/logback/base.xml"/&gt;
      &lt;appender name="fluent" class="com.example.demo.FluentLogbackAppender"/&gt;
      &lt;root level="info" additivity="false"&gt;
          &lt;appender-ref ref="fluent" /&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Adding the dependency in pom.xml</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.fluentd&lt;/groupId&gt;
      &lt;artifactId&gt;fluent-logger&lt;/artifactId&gt;
      &lt;version&gt;0.3.3&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I have stripped some code to make it simple.
  When running this, I am presented with </p>
  
  <pre><code>2018-05-22 14:39:42.190 ERROR 18788 --- [           main] o.s.boot.SpringApplication               : Application run failed
  
  java.lang.IllegalStateException: Logback configuration error detected:
  ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:77 - RuntimeException in Action for tag [appender] java.lang.NullPointerException
          at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:166)
          at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:212)
          at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:75)
          at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
          at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114)
          at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:264)
          at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237)
          at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
          at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
          at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
          at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
          at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
          at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
          at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
          at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
          at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
          at com.example.demo.DemoApplication.main(DemoApplication.java:10)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
          at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
          at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
          at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
  </code></pre>
  
  <p>NullPointerException is returned from sender.emit() inside FluentLogger class.
  The interesting thing is, this code actually pushes the data to fluentd aggregator just before crash.
  Is there any way to make this work.</p>