Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the hibernate logging level in JHipster?

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:

  • Is it possible to configure the log level for an individual REST call?
  • How can I globally configure the log levels for the application?
like image 621
nezuvian Avatar asked Mar 18 '15 16:03

nezuvian


People also ask

How do you change the logging level?

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)

What logger does hibernate use?

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.


2 Answers

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>
like image 112
Abdull Avatar answered Oct 18 '22 13:10

Abdull


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?

like image 37
sdoxsee Avatar answered Oct 18 '22 12:10

sdoxsee