I am trying to log raw request/response from a http client. I am following log4j2 configurations from these logging instructions.
HttpAsync Client Dependency :- httpasyncclient (version 4.1.1)
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<RollingRandomAccessFile name="app-log" fileName="${log.path}/app.log"
filePattern="${log.path}/app-%d{yyyy-MM-dd}.gz">
<PatternLayout>
<pattern>[%-5level] [%X{uuid}] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<AsyncLogger name="org.apache.http.impl.conn.Wire" level="debug">
<AppenderRef ref="app-log"/>
</AsyncLogger>
<AsyncRoot level="debug" includeLocation="true">
<AppenderRef ref="app-log"/>
</AsyncRoot>
</Loggers>
</Configuration>
It is printing fine but the threadcontext is not passing onto the wire logger.
Example :-
// 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 >> POST /abcd.json HTTP/1.1
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 >> Content-Length: 2
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 >> Content-Type: text/plain; charset=ISO-8859-1
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 >> Host: 127.0.0.1:80
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] [] 2016-11-14 17:06:03.441 [I/O dispatcher 1] headers - http-outgoing-0 >> User-Agent: Apache-HttpAsyncClient/4.1.1 (Java/1.8.0_92)
How can I pass the ThreadContext to the logger?
Thanks.