我使用的是最新版本的spring data cassandra,它使用datastax 4.6
在旧版本中,有一种方法可以使用QueryLogger和Cluster来记录较慢和正常的查询
然而,我找不到在新版本中记录查询和时间的方法
在新版本中,QueryLogger不再可用,取而代之的是RequestTracker
Java驱动程序提供了RequestTracker接口。您可以指定通过在中配置属性来拥有或使用提供的RequestLogger实现datatax-java-driver.advanced.request-tracker命名空间。RequestLogger跟踪查询您的应用程序执行并具有启用成功、失败和慢速日志记录的选项查询。使用慢速查询记录器来识别不在您定义的性能范围内的查询。
配置:
datastax-java-driver.advanced.request-tracker {
class = RequestLogger
logs {
# Whether to log successful requests.
success.enabled = true
slow {
# The threshold to classify a successful request as "slow". If this is unset, all
# successful requests will be considered as normal.
threshold = 1 second
# Whether to log slow requests.
enabled = true
}
# Whether to log failed requests.
error.enabled = true
# The maximum length of the query string in the log message. If it is longer than that, it
# will be truncated.
max-query-length = 500
# Whether to log bound values in addition to the query string.
show-values = true
# The maximum length for bound values in the log message. If the formatted representation of
# a value is longer than that, it will be truncated.
max-value-length = 50
# The maximum number of bound values to log. If a request has more values, the list of
# values will be truncated.
max-values = 50
# Whether to log stack traces for failed queries. If this is disabled, the log will just
# include the exception's string representation (generally the class name and message).
show-stack-traces = true
}
更多详细信息。