Recently I had some issues with Elasticsearch - all requests were failing with “bad request” error. In order to understand what was wrong with these requests, I, natually, decided to enable debug/trace logging of for ES REST Client, but couldn’t find out how. Partially, because the official documentation on this topic could have been more informative, to be honest. But mainly, because my project uses Logback and the REST Client package uses Apache Commons Logging.
This article is a short summary of how I’ve eventually managed to enable tracing with Logback. The patient under inspection is Elasticsearch 6.3 with its Java Low Level REST Client.
According to the official documentation, we need to enable trace logging for the tracer
package. If you are interested, you can check the source code for org.elasticsearch.client.RequestLogger class, where the logger with this name is defined:
As you can see, enabling this logger with TRACE
level in Logback is not enough, because, again, the client uses Apache Commons Logging.
Luckily, Logback was designed with this use case in mind, and provides a set of bridging modules. They allow us to use Logback even with other dependencies that rely on other logging API. In particular, we’re looking for jcl-over-slf4j.jar.
So, here are the steps.
Require jcl-over-slf4j.jar
. The dependencies section for Gradle:
Exclude commons-logging.jar
. The details of why are described in the Logback docs here.
Enable tracer logger in Logback configuration.
Voilà! Enjoy your debugging session!