DataStax driver logs

DataStax drivers support client-side and server-side logging.

Configure logging in DataStax drivers

DataStax recommends starting with INFO level logging for drivers in most production use cases. When debugging, DataStax recommends lowering the log level of the modules based on the purpose of the investigation.

C/C++ driver logging
C# driver logging
GoCQL driver logging

GoCQL supports the standard Go package log. To enable debug logging, you must use the build tag gocql_debug, meaning using go build -tags gocql_debug command to build your project.

You can also customize the logger by specifying Cluster.Logger:

Example: Custom logger
import (
	"github.com/gocql/gocql"
	"log"
	"os"
)
cluster := gocql.NewCluster("127.0.0.1:9043", "127.0.0.1:9044", "127.0.0.1:9045")
cluster.Logger = log.New(os.Stdout, "gocql: ", log.LstdFlags)
session, err := cluster.CreateSession()
Example: Log output
gocql: 2024/11/05 15:40:18 gocql: Session.handleNodeConnected: 127.0.0.1:9044
gocql: 2024/11/05 15:40:18 gocql: Session.handleNodeConnected: 127.0.0.1:9045
gocql: 2024/11/05 15:40:18 gocql: conns of pool after stopped "127.0.0.1": 2
gocql: 2024/11/05 15:40:18 gocql: conns of pool after stopped "127.0.0.1": 2
gocql: 2024/11/05 15:40:18 gocql: Session.handleNodeConnected: 127.0.0.1:9043
gocql: 2024/11/05 15:40:18 gocql: conns of pool after stopped "127.0.0.1": 2
Java driver logging

When troubleshooting topology changes with Java driver 4.x, enable the following loggers:

com.datastax.oss.driver.internal.core.session.PoolManager = DEBUG
com.datastax.oss.driver.internal.core.pool.ChannelPool = DEBUG
com.datastax.oss.driver.internal.core.metadata.NodeStateManager = DEBUG
com.datastax.oss.driver.internal.core.metadata.MetadataManager = DEBUG
com.datastax.oss.driver.internal.core.util.concurrent.Reconnection = DEBUG

To log topology changes with Java driver 3.x, enable the following loggers:

com.datastax.driver.core.Host.STATES = TRACE
com.datastax.driver.core.Cluster = TRACE
com.datastax.driver.core.Connection = DEBUG
com.datastax.driver.core.ControlConnection = DEBUG
com.datastax.driver.core.HostConnectionPool = DEBUG
com.datastax.driver.core.RequestHandler = DEBUG
com.datastax.driver.core.EventDebouncer = TRACE

For more information, see the following:

Node.js driver logging
PHP driver logging

For information about PHP driver logging, see the documentation for the PHP driver logging feature and the PHP driver Logging class.

Python driver logging

The DataStax Python driver uses the Python built-in logging library.

Example: Basic logging configuration
import logging
def config_logger():
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    # setting default log level for the whole driver
    logging.getLogger('cassandra').setLevel(logging.INFO)
    # example to debug topology events
    logging.getLogger(metadata.__name__).setLevel(logging.DEBUG)
    logging.getLogger(cluster.__name__).setLevel(logging.DEBUG)
Example: Logging topology changes
from cassandra import metadata, cluster, connection
def config_logger():
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    # setting default log level for the whole driver
    logging.getLogger('cassandra').setLevel(logging.INFO)
    # example to debug topology events
    logging.getLogger(metadata.__name__).setLevel(logging.DEBUG)
    logging.getLogger(cluster.__name__).setLevel(logging.DEBUG)
    logging.getLogger(connection.__name__).setLevel(logging.DEBUG)
Ruby driver logging

For information about Ruby driver logging, see the documentation for the Ruby driver logging feature and the Ruby driver Logger class.

Configure statement execution logs

To track client-side events related to query execution, DataStax drivers support statement execution logs, which are also known as query observation or request tracking.

To trace internal changes to a database that result from query execution, see Configure request tracing.

C# driver custom request tracking

The C# driver’s built-in IRequestTracker is for open telemetry tracing. However, you can write your own and provide it to the driver.

GoCQL driver QueryObserver

To debug individual CQL statements, you can implement the QueryObserver interface, and then attach your query observer to the query:

type myQueryObserver struct {
	logger log.Logger
}

func (o *myQueryObserver) ObserveQuery(ctx context.Context, q gocql.ObservedQuery) {
	o.logger.Printf("Query: %s, Latency: %v, Host: %s\n", q.Statement, q.Metrics.TotalLatency, q.Host.HostnameAndPort())
}

func main() {
	cluster := gocql.NewCluster("127.0.0.1:9043", "127.0.0.1:9044", "127.0.0.1:9045")
	cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.DCAwareRoundRobinPolicy("datacenter1"))
	session, err := cluster.CreateSession()
	if err != nil {
		log.Fatalf("Error creating session: %v\n", err)
		return
	}
	defer session.Close()
	queryObserver := &myQueryObserver{logger: *log.New(os.Stdout, "QueryObserver: ", log.LstdFlags)}
	ctx := context.Background()
	session.Query("SELECT host_id, broadcast_address FROM system.local").WithContext(ctx).Observer(queryObserver).Iter().Scanner()
}
Example: QueryObserver output
QueryObserver: 2024/11/06 14:22:40 Query: SELECT host_id,
broadcast_address FROM system.local,
Latency: 3843583,
Host: 127.0.0.1:9044
Java driver RequestLogger

In the Java driver, you can enable CQL statement logging with RequestLogger.

You can also implement your own RequestTracker to get notified when a CQL statement is executed and get information about the result.

Custom RequestTracker implementations must be non-blocking and not perform I/O operations in performance-critical sections of code.

datastax-java-driver {
  advanced.request-tracker {
    classes = [RequestLogger]
    logs {
      success.enabled = true
      slow {
        threshold = 1 second
        enabled = true
      }
      error.enabled = true
      max-query-length = 500
      show-values = true
      max-value-length = 50
      max-values = 50
      show-stack-traces = false
    }
  }
}
Node.js driver RequestTracker
Python driver request listener

Use session.add_request_init_listener to log each request:

from cassandra.cluster import Cluster
from cassandra import metadata, cluster, connection
import logging
from cassandra.policies import DCAwareRoundRobinPolicy, TokenAwarePolicy
def config_logger():
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    # setting default log level for the whole driver
    logging.getLogger('cassandra').setLevel(logging.INFO)
    # example to debug topology events
    logging.getLogger(metadata.__name__).setLevel(logging.DEBUG)
    logging.getLogger(cluster.__name__).setLevel(logging.DEBUG)
    logging.getLogger(connection.__name__).setLevel(logging.DEBUG)
def request_logger(rf: cluster.ResponseFuture):
    logger = logging.getLogger(__name__)
    def on_success(_, response_future: cluster.ResponseFuture):
        logger.debug("Success: %s; coordinator: %s", response_future.query, response_future.coordinator_host)
    def on_error(_, response_future: cluster.ResponseFuture):
        logger.warning("Error: %s; coordinator: %s", response_future.query, response_future.coordinator_host)
    rf.add_callbacks(on_success, on_error, callback_args=(rf,), errback_args=(rf,))
if __name__ == '__main__':
    config_logger()
    cl = Cluster(['127.0.0.1'], port=9043, protocol_version=5,
                 load_balancing_policy=TokenAwarePolicy(DCAwareRoundRobinPolicy(local_dc='datacenter1')))
    session = cl.connect()
    session.add_request_init_listener(request_logger)
    rows = session.execute('SELECT * FROM system.local')

For more information, see cassandra.cluster.

Configure request tracing

To track internal changes to a database that result from query execution, DataStax drivers support request tracing, which is also known as query tracing.

This is comparable to the CQL statement TRACING ON.

To log client-side events related to query execution, see Configure statement execution logs.

C/C++ driver request tracing
C# driver request tracing

You can set the tracing flag in your statement execution attributes. For more information, see C# driver statements and QueryTrace.

GoCQL driver request tracing

Use func (*Query) Trace. For more information, see the Tracer interface.

Java driver query tracing
Node.js driver request tracing

Use traceQuery in QueryOptions.

Python driver QueryTrace

See QueryTrace.

Ruby driver request tracing

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com