Pass context to async Logger
<p>I am trying to log raw request/response from a http client.
I am following log4j2 configurations from these <a href="http://hc.apache.org/httpcomponents-client-4.3.x/logging.html" rel="nofollow noreferrer">logging instructions</a>.</p>
<p>HttpAsync Client Dependency :- httpasyncclient (version 4.1.1)</p>
<p>log4j2.xml</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Configuration status=&quot;WARN&quot;&gt;
&lt;Appenders&gt;
    &lt;RollingRandomAccessFile name=&quot;app-log&quot; fileName=&quot;${log.path}/app.log&quot;
                             filePattern=&quot;${log.path}/app-%d{yyyy-MM-dd}.gz&quot;&gt;
        &lt;PatternLayout&gt;
            &lt;pattern&gt;[%-5level] [%X{uuid}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n&lt;/pattern&gt;
        &lt;/PatternLayout&gt;
        &lt;Policies&gt;
            &lt;TimeBasedTriggeringPolicy interval=&quot;1&quot; modulate=&quot;true&quot;/&gt;
        &lt;/Policies&gt;
    &lt;/RollingRandomAccessFile&gt;
&lt;/Appenders&gt;
&lt;Loggers&gt;
    &lt;AsyncLogger name=&quot;org.apache.http.impl.conn.Wire&quot; level=&quot;debug&quot;&gt;
        &lt;AppenderRef ref=&quot;app-log&quot;/&gt;
    &lt;/AsyncLogger&gt;
    &lt;AsyncRoot level=&quot;debug&quot; includeLocation=&quot;true&quot;&gt;
        &lt;AppenderRef ref=&quot;app-log&quot;/&gt;
    &lt;/AsyncRoot&gt;
&lt;/Loggers&gt;
&lt;/Configuration&gt;
</code></pre>
<p>It is printing fine but the threadcontext is not passing onto the wire logger.</p>
<p>Example :-</p>
<pre><code>// with uuid, output of logger.debug(ThreadContext.getImmutableContext().toString());

[DEBUG] [c48b97f7-0094-44af-82af-3d6b43d76014] 2016-11-14 17:06:03.408 [http-bio-8080-exec-1] OutboundRequestHandler - {uuid=c48b97f7-0094-44af-82af-3d6b43d76014}

// without uuid
[DEBUG] [] 2016-11-14 17:06:03.440 [I/O dispatcher 1] headers - http-outgoing-0 &gt;&gt; POST /abcd.json HTTP/1.1
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 &gt;&gt; Content-Length: 2
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 &gt;&gt; Content-Type: text/plain; charset=ISO-8859-1
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 &gt;&gt; Host: 127.0.0.1:80
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 &gt;&gt; Connection: Keep-Alive
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 &gt;&gt; User-Agent: Apache-HttpAsyncClient/4.1.1 (Java/1.8.0_92)
</code></pre>
<p>How can I pass the ThreadContext to the logger?</p>
<p>Thanks.</p>