【问题标题】:Spring Cassandra 3.0.1.RELEASE( Datastax 4.6+) log queriesSpring Cassandra 3.0.1.RELEASE(Datastax 4.6+) 日志查询
【发布时间】:2024-01-17 09:30:01
【问题描述】:

我正在使用最新版本的 spring data cassandra,它使用 datastax 4.6

在旧版本中,有一种方法可以使用 QueryLoggerCluster

记录较慢和正常的查询

但是我无法找到记录查询和更新版本所用时间的方法

【问题讨论】:

    标签: spring-boot cassandra spring-data datastax-java-driver spring-data-cassandra


    【解决方案1】:

    在较新的版本中,QueryLogger 不再可用,它已被 RequestTracker

    取代

    Java 驱动程序提供了一个 RequestTracker 接口。您可以指定您的实现 通过配置属性来拥有或使用提供的 RequestLogger 实现 datastax-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
    }
    

    More details.

    【讨论】: