Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Java REST Client logging in Elasticsearch in Curl format

I'm using org.elasticsearch.client.RestHighLevelClient to run queries.

According to the official documentation, it's possible to log requests in curl format:

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-logging.html

I have added the following line to my log4j.properties:

log4j.logger.org.elasticsearch.client = debug

Now I see http requests, but, how can I set curl formatting?

like image 956
josmaf Avatar asked Aug 21 '26 14:08

josmaf


2 Answers

According to their documentation, you need to enable specific tracer logger, that is responsible specifically for curl format response.

You could achieve this in log4j 1.x with following lines:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] %c{1}:%L - %m%n

log4j.logger.tracer=TRACE, stdout
like image 112
Mysterion Avatar answered Aug 24 '26 04:08

Mysterion


Just in case someone doesn't want to bother oneself with loggers, it's possible to call toString() on QueryBuilder and see a request.

like image 31
GlaIZier Avatar answered Aug 24 '26 04:08

GlaIZier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!