I have a use case in which I run multiple thousand SQL queries and the logging set as it is, writing every query out to the console takes a lot of time and makes the call time out on the client side. I tried setting the logback.loglevel property of the dev profile in the pom.xml to ERROR but that didn't help.
So my questions are:
To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)
Hibernate utilizes Simple Logging Facade for Java (SLF4J) in order to log various system events. SLF4J can direct your logging output to several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your chosen binding.
Besides changing the property spring.jpa.show_sql
in application*.yml
files, you can also try changing Logback's configurations:
In the files src/main/resources/logback-spring.xml
and src/test/resources/logback-test.xml
you can add the following configurations:
To get detailed log SQL information including SQL parameter values:
<logger name="org.hibernate.SQL" level="DEBUG"/>
<logger name="org.hibernate.type" level="TRACE"/>
To make SQL less chatty:
<logger name="org.hibernate.SQL" level="DEBUG"/>
<logger name="org.hibernate.type" level="TRACE"/>
As an added bonus, explicitly declaring these loggers in logback configuration files will make Hibernate's logging use Logback's layout configuration, e.g. showing the time and the name of the executing thread.
spring.jpa.show_sql
set to true
takes precedence over the Logback configuration - including its less helpful layout without time and without the name of the execuding thread. So for my own purposes, I prefer to set spring.jpa.show_sql
to false
and instead configure logback-spring.xml
(where logging configuration aspects should be placed anyways). There, you can then set Spring profile-specific logging levels:
<springProfile name="dev, staging">
<logger name="org.hibernate.SQL" level="DEBUG"/> <!-- set org.hibernate.SQL to DEBUG to see SQL statements -->
<logger name="org.hibernate.type" level="INFO"/> <!-- set org.hibernate.type to TRACE to see SQL parameters -->
</springProfile>
<springProfile name="prod">
<logger name="org.hibernate.SQL" level="INFO"/> <!-- set org.hibernate.SQL to DEBUG to see SQL statements -->
<logger name="org.hibernate.type" level="INFO"/> <!-- set org.hibernate.type to TRACE to see SQL parameters -->
</springProfile>
Is changing spring.jpa.show_sql: true in https://github.com/jhipster/jhipster-sample-app/blob/v6.10.5/src/main/resources/config/application-dev.yml#L51 to 'false' what you're looking for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With