How to Log Cassandra Queries in Java Spring

To enable logging for cassandra queries with Spring Data and the datastax driver you first need to register a QueryLogger instance with your cluster:

1
2
QueryLogger queryLogger = QueryLogger.builder().build();
cluster.register(queryLogger);

You also need to specify the log levels for the QueryLogger in your properties:

1
2
3
logging.level.com.datastax.driver.core.QueryLogger.NORMAL=DEBUG
logging.level.com.datastax.driver.core.QueryLogger.SLOW=DEBUG
logging.level.com.datastax.driver.core.QueryLogger.ERROR=DEBUG

While you might not always to turn logging on for NORMAL or even SLOW it can ease debugging a lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.