问题
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