How to log Spring-data queries to a Couchbase Database

最后都变了- 提交于 2020-02-25 08:08:26

问题


In my Spring-Boot app we have a Spring-Data repository connection to the Couchbase server.

I know that when connecting to SQL server, one can see the actual queries sent to the DB by adding to the property file line such as this one (As mentioned here):

logging.level.org.hibernate.SQL=DEBUG

What should be the way to do it when using Couchbase?


回答1:


Add logback as your dependency

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>

and add the file logback.xml to your resources folder:

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<root level="debug">
    <appender-ref ref="STDOUT" />
</root>

If I remember it correctly, you can enable dubug level only in the class that prints the query with the following configuration:

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<logger name="org.springframework.data.couchbase.repository.query" level="debug" />

<root level="info">
    <appender-ref ref="STDOUT" />
</root>




回答2:


Following deniswasrosa's answer I was able to see the queries just by adding this to the yml file:

logging:
   level:  
     org.springframework.data.couchbase.repository.query: DEBUG

I had no need to add the dependency.



来源:https://stackoverflow.com/questions/53373431/how-to-log-spring-data-queries-to-a-couchbase-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!