elasticsearch logging doc seems too ambiguous, but it mentions tracer
:
Enable trace logging for the tracer package to have such log lines printed out.
If you dive into the es client code, there is a class called org.apache.http.util.EntityUtils.RequestLogger
, which logs all the requests and responses detail into a logger named tracer
:
private static final Log tracer = LogFactory.getLog("tracer");
In method logResponse
, you can see that it logs debug info into normal package logger, trace info into tracer
logger.
So the right way to show request & response trace info is to configure a logger named tracer
, and enable TRACE
level for it.
Using logback.xml
for example:
<appender name="ES_REQ_RES_TRACER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/es-trace</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/es-trace.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxHistory>3</maxHistory>
<maxFileSize>500MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<logger name="tracer" additivity="false" level="trace">
<appender-ref ref="ES_REQ_RES_TRACER" />
</logger>
Now you can find trace details in logs/es-trace
file. It will contains a curl request and a json response.
TRACE
level for tracer
logger can also be configured in application.properties
if you use spring boot:
logging.level.tracer=TRACE