title: Why I can't send message to kafka through AsyncLogger/AsyncAppender with FailoverAppender?
body: <p>I'm trying to write a demo to test <strong>asynclog</strong> but I realized <strong>it didn't work sending a message to kafka</strong>. Wha should I do to make it work ?  code will paste in behind.<br> <br>
  <strong>add: this situation should tell you.</strong> when I added a <code>Thread.sleep(1000)</code> in my async test main class today and <strong>it works</strong> but won't trigger failover  ref appender ,whatever I set kafka syncSend to true/false it didn't work.<br>
   <br>
  Here are some other problems I want to ask for:)</p>
  
  <ol>
  <li><p>if i use async to send log to kafka as <strong>audit logging framework</strong> could it 
  <strong>guarantee reliability</strong>? <br>
  Because in here <a href="http://logging.apache.org/log4j/2.x/manual/async.html" rel="nofollow noreferrer">log4j2</a> it says  <br>
  "recommend to synchronously log those audit messages."</p></li>
  <li><p>In <strong>sync</strong> situation I've use a <strong>failoverappender</strong> to save lose messages in 
  local disk file.But may i have a better way to resend these messages to 
  kafka?did it work in async situation?
  Because now i can't delete the file and i use the filebeat to scan 
  the file and send to logstash.</p></li>
  <li><p>I've made a Util to Packaging interface of log4j2,and in this way it can't get right location message in log4j2.xml PatternLayout like "%C %M %F %L",and i then use <br>
  <code>"Thread.currentThread().getStackTrace()[3];"</code><br>
  in my util class to get these message (Internally called other methods so the index was 3) and splice String to send log message like this:
  <code>"logger.error(MarkerManager.getMarker("MESSAGE"),"Class: {}   Method: {} File: {}  Line: {} ---{}",X,X,X,X,JSON.toJSONString(X));"</code><br>
  May I've a better way to optimization these code and get these location information?</p></li>
  </ol>
  
  <p>I test on windows OS, I'm using java language, spring boot project.
  Here there are some base pom dependencies:</p>
  
  <pre><code>    &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.alibaba&lt;/groupId&gt;
              &lt;artifactId&gt;fastjson&lt;/artifactId&gt;
              &lt;version&gt;1.2.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
              &lt;version&gt;2.1.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;
              &lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;
              &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.lmax&lt;/groupId&gt;
              &lt;artifactId&gt;disruptor&lt;/artifactId&gt;
              &lt;version&gt;3.4.2&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>log4j2.xml:</p>
  
  <pre><code>&lt;configuration status="debug" monitorInterval="10"&gt;
      &lt;properties&gt;
          &lt;property name="LOG_HOME"&gt;logs/TESTPROJECT&lt;/property&gt;
          &lt;property name="PATTERN_LAYOUT_CONSOLE"&gt;%d{DEFAULT} [%t] %-5level --- %msg %xEx%n&lt;/property&gt;
          &lt;property name="PATTERN_LAYOUT_CONSOLE_ROOT"&gt;%d{DEFAULT} [%t] %-5level --- Class: %C Method: %M File: %F Line:
              %L --- %msg %xEx%n
          &lt;/property&gt;
          &lt;property name="PATTERN_LAYOUT"&gt;%d{DEFAULT} [%t] %-5level --- %msg %xEx%n&lt;/property&gt;
      &lt;/properties&gt;
      &lt;appenders&gt;
          &lt;Console name="Console" target="SYSTEM_OUT"&gt;
              &lt;ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/&gt;
              &lt;PatternLayout charset="utf-8"&gt;
                  &lt;MarkerPatternSelector defaultPattern="${PATTERN_LAYOUT_CONSOLE_ROOT}"&gt;
                      &lt;PatternMatch key="UTIL" pattern="${PATTERN_LAYOUT_CONSOLE}"/&gt;
                      &lt;PatternMatch key="TRACE" pattern="${PATTERN_LAYOUT_CONSOLE}"/&gt;
                      &lt;PatternMatch key="MESSAGE" pattern="${PATTERN_LAYOUT_CONSOLE}"/&gt;
                  &lt;/MarkerPatternSelector&gt;
              &lt;/PatternLayout&gt;
          &lt;/Console&gt;
          &lt;RollingRandomAccessFile name="RollingRandomAccessFileInfo" fileName="${LOG_HOME}/info.log"
                                   filePattern="${LOG_HOME}/$${date:yyyy-MM}/$${date:yyyy-MM-dd}/info/info-%d{yyyy-MM-dd}-%i.log.gz"
                                   bufferSize="4096" immediateFlush="false" bufferedIO="true" append="true"&gt;
              &lt;Filters&gt;
                  &lt;ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/&gt;
                  &lt;ThresholdFilter level="INFO"/&gt;
              &lt;/Filters&gt;
              &lt;PatternLayout charset="utf-8"&gt;
                  &lt;MarkerPatternSelector defaultPattern="${PATTERN_LAYOUT_CONSOLE_ROOT}"&gt;
                      &lt;PatternMatch key="UTIL" pattern="${PATTERN_LAYOUT}"/&gt;
                      &lt;PatternMatch key="TRACE" pattern="${PATTERN_LAYOUT}"/&gt;
                      &lt;PatternMatch key="MESSAGE" pattern="${PATTERN_LAYOUT}"/&gt;
                  &lt;/MarkerPatternSelector&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;CronTriggeringPolicy schedule="0 0 0/12 * * ?"/&gt;
                  &lt;TimeBasedTriggeringPolicy/&gt;
                  &lt;SizeBasedTriggeringPolicy size="100 MB"/&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="50"&gt;
                  &lt;Delete basePath="${LOG_HOME}" testMode="true" maxDepth="5"&gt;
                      &lt;IfFileName glob="*/*/info/info-*.log.gz"&gt;
                          &lt;IfLastModified age="180d"&gt;
                              &lt;IfAny&gt;
                                  &lt;IfAccumulatedFileSize exceeds="50GB"/&gt;
                                  &lt;IfAccumulatedFileCount exceeds="1000"/&gt;
                              &lt;/IfAny&gt;
                          &lt;/IfLastModified&gt;
                      &lt;/IfFileName&gt;
                  &lt;/Delete&gt;
              &lt;/DefaultRolloverStrategy&gt;
          &lt;/RollingRandomAccessFile&gt;
  
          &lt;RollingRandomAccessFile name="RollingRandomAccessFileWarn" fileName="${LOG_HOME}/warn.log"
                                   filePattern="${LOG_HOME}/$${date:yyyy-MM}/$${date:yyyy-MM-dd}/warn/warn-%d{yyyy-MM-dd}-%i.log.gz"
                                   bufferSize="4096" immediateFlush="false" bufferedIO="true" append="true"&gt;
              &lt;Filters&gt;
                  &lt;ThresholdFilter level="WARN"/&gt;
                  &lt;ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/&gt;
              &lt;/Filters&gt;
              &lt;PatternLayout charset="utf-8"&gt;
                  &lt;MarkerPatternSelector defaultPattern="${PATTERN_LAYOUT_CONSOLE_ROOT}"&gt;
                      &lt;PatternMatch key="UTIL" pattern="${PATTERN_LAYOUT}"/&gt;
                      &lt;PatternMatch key="TRACE" pattern="${PATTERN_LAYOUT}"/&gt;
                      &lt;PatternMatch key="MESSAGE" pattern="${PATTERN_LAYOUT}"/&gt;
                  &lt;/MarkerPatternSelector&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;CronTriggeringPolicy schedule="0 0 0/12 * * ?"/&gt;
                  &lt;TimeBasedTriggeringPolicy/&gt;
                  &lt;SizeBasedTriggeringPolicy size="100 MB"/&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="50"&gt;
                  &lt;Delete basePath="${LOG_HOME}" testMode="true" maxDepth="5"&gt;
                      &lt;IfFileName glob="*/*/warn/warn*.log.gz"&gt;
                          &lt;IfLastModified age="180d"&gt;
                              &lt;IfAny&gt;
                                  &lt;IfAccumulatedFileSize exceeds="50GB"/&gt;
                                  &lt;IfAccumulatedFileCount exceeds="1000"/&gt;
                              &lt;/IfAny&gt;
                          &lt;/IfLastModified&gt;
                      &lt;/IfFileName&gt;
                  &lt;/Delete&gt;
              &lt;/DefaultRolloverStrategy&gt;
          &lt;/RollingRandomAccessFile&gt;
          &lt;RollingRandomAccessFile name="RollingRandomAccessFileError" fileName="${LOG_HOME}/error.log"
                                   filePattern="${LOG_HOME}/$${date:yyyy-MM}/$${date:yyyy-MM-dd}/error/error-%d{yyyy-MM-dd}-%i.log.gz"
                                   append="true"&gt;
              &lt;ThresholdFilter level="ERROR"/&gt;
              &lt;PatternLayout charset="utf-8"&gt;
                  &lt;MarkerPatternSelector defaultPattern="${PATTERN_LAYOUT_CONSOLE_ROOT}"&gt;
                      &lt;PatternMatch key="UTIL" pattern="${PATTERN_LAYOUT}"/&gt;
                      &lt;PatternMatch key="TRACE" pattern="${PATTERN_LAYOUT}"/&gt;
                      &lt;PatternMatch key="MESSAGE" pattern="${PATTERN_LAYOUT}"/&gt;
                  &lt;/MarkerPatternSelector&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;CronTriggeringPolicy schedule="0 0 0/12 * * ?"/&gt;
                  &lt;TimeBasedTriggeringPolicy/&gt;
                  &lt;SizeBasedTriggeringPolicy size="100 MB"/&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="50"&gt;
                  &lt;Delete basePath="${LOG_HOME}" testMode="true" maxDepth="5"&gt;
                      &lt;IfFileName glob="*/*/error/error*.log.gz"&gt;
                          &lt;IfLastModified age="180d"&gt;
                              &lt;IfAny&gt;
                                  &lt;IfAccumulatedFileSize exceeds="50GB"/&gt;
                                  &lt;IfAccumulatedFileCount exceeds="1000"/&gt;
                              &lt;/IfAny&gt;
                          &lt;/IfLastModified&gt;
                      &lt;/IfFileName&gt;
                  &lt;/Delete&gt;
              &lt;/DefaultRolloverStrategy&gt;
          &lt;/RollingRandomAccessFile&gt;
          &lt;Kafka name="KafkaSync" topic="yi-test" syncSend="false" ignoreExceptions="false"&gt;
              &lt;MarkerFilter marker="MESSAGE" onMatch="ACCEPT" onMismatch="DENY"/&gt;
              &lt;PatternLayout charset="utf-8" pattern="${PATTERN_LAYOUT}"/&gt;
              &lt;ThresholdFilter level="ERROR"/&gt;
              &lt;Property name="bootstrap.servers"&gt;192.100.2.44:9092,192.100.2.45:9092&lt;/Property&gt;
              &lt;Property name="timeout.ms"&gt;3000&lt;/Property&gt;
              &lt;Property name="max.block.ms"&gt;2000&lt;/Property&gt;
          &lt;/Kafka&gt;
          &lt;Kafka name="KafkaTrace" topic="yi-test2" syncSend="false" ignoreExceptions="false"&gt;
              &lt;MarkerFilter marker="TRACE" onMatch="ACCEPT" onMismatch="DENY"/&gt;
              &lt;PatternLayout charset="utf-8" pattern="${PATTERN_LAYOUT}"/&gt;
              &lt;ThresholdFilter level="ERROR"/&gt;
              &lt;Property name="bootstrap.servers"&gt;192.100.2.44:9092,192.100.2.45:9092&lt;/Property&gt;
              &lt;Property name="timeout.ms"&gt;3000&lt;/Property&gt;
              &lt;Property name="max.block.ms"&gt;2000&lt;/Property&gt;
          &lt;/Kafka&gt;
          &lt;File name="failoverKafkaLog" fileName="${LOG_HOME}/failover.log"
                ignoreExceptions="false"&gt;
              &lt;MarkerFilter marker="MESSAGE" onMatch="ACCEPT" onMismatch="DENY"/&gt;
              &lt;PatternLayout charset="utf-8" pattern="${PATTERN_LAYOUT}"/&gt;
          &lt;/File&gt;
          &lt;File name="failoverKafkaTraceLog" fileName="${LOG_HOME}/failoverTrace.log"
                ignoreExceptions="false"&gt;
              &lt;MarkerFilter marker="TRACE" onMatch="ACCEPT" onMismatch="DENY"/&gt;
              &lt;PatternLayout charset="utf-8" pattern="${PATTERN_LAYOUT}"/&gt;
          &lt;/File&gt;
          &lt;Failover name="Failover" primary="KafkaSync" retryIntervalSeconds="15"&gt;
              &lt;Failovers&gt;
                  &lt;appender-ref ref="failoverKafkaLog"/&gt;
              &lt;/Failovers&gt;
          &lt;/Failover&gt;
          &lt;Failover name="FailoverTrace" primary="KafkaTrace" retryIntervalSeconds="15"&gt;
              &lt;Failovers&gt;
                  &lt;appender-ref ref="failoverKafkaTraceLog"/&gt;
              &lt;/Failovers&gt;
          &lt;/Failover&gt;
          &lt;Async name="AsyncKafka"&gt;
              &lt;appender-ref ref="Failover"/&gt;
              &lt;appender-ref ref="FailoverTrace"/&gt;
          &lt;/Async&gt;
      &lt;/appenders&gt;
      &lt;loggers&gt;
          &lt;AsyncLogger name="com.logtest.demo" level="debug" includeLocation="true" additivity="false"&gt;
              &lt;!--i have tried all these ref situations and no one work --&gt;
              &lt;appender-ref ref="Failover"/&gt;
              &lt;appender-ref ref="FailoverTrace"/&gt;
              &lt;!--&lt;appender-ref ref="KafkaSync"/&gt;--&gt;
              &lt;!--&lt;appender-ref ref="KafkaTrace"/&gt;--&gt;
              &lt;!--&lt;appender-ref ref="AsyncKafka"/&gt;--&gt;
              &lt;appender-ref ref="RollingRandomAccessFileInfo"/&gt;
              &lt;appender-ref ref="RollingRandomAccessFileWarn"/&gt;
              &lt;appender-ref ref="RollingRandomAccessFileError"/&gt;
          &lt;/AsyncLogger&gt;
          &lt;root level="info" includeLocation="true"&gt;
              &lt;appender-ref ref="Console"/&gt;
          &lt;/root&gt;
          &lt;Logger name="org.apache.kafka" level="INFO"/&gt; &lt;!-- avoid recursive logging --&gt;
      &lt;/loggers&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is the log when I run test class and set log4j2 configuration level to debug :
  the log file i push to my github <a href="https://github.com/lMasterSparkl/lgo4j2asynctestlog/blob/master/log4j2.log" rel="nofollow noreferrer">mygithub</a>
  because my it limited the body limited :(</p>