如何在JHipster中更改休眠日志记录级别?

nez*_*ian 6 logging hibernate jhipster

我有一个用例,其中我运行了数千个SQL查询,并且按原样运行了日志集,将每个查询写到控制台会花费很多时间,并使调用超时在客户端进行。我尝试将pom.xml中的开发人员配置文件的logback.loglevel属性设置为ERROR,但这没有帮助。

所以我的问题是:

  • 是否可以为单个REST调用配置日志级别?
  • 如何全局配置应用程序的日志级别?

Abd*_*ull 6

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"/>
Run Code Online (Sandbox Code Playgroud)

To make SQL less chatty:

<logger name="org.hibernate.SQL" level="DEBUG"/>
<logger name="org.hibernate.type" level="TRACE"/>
Run Code Online (Sandbox Code Playgroud)

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设置为true优先于 Logback 配置 - 包括它没有时间和没有执行线程名称的不太有用的布局。所以出于我自己的目的,我更喜欢设置spring.jpa.show_sqlfalse而不是配置logback-spring.xml(无论如何都应该放置日志配置方面)。在那里,您可以设置特定于 Spring 配置文件的日志记录级别

<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>
Run Code Online (Sandbox Code Playgroud)