SoFunction
Updated on 2025-03-08

Log4j closes Spring and Hibernate log printing method

Log4j Close Spring and Hibernate log printing

The closing mentioned here is not all without printing, you just need to modify the log level.

We don’t actually read ordinary info information, so we just set it to the warning or error level directly.

#close java-jdbc log out
=ERROR
=ERROR
=ERROR

#close spring log out
=WARN

#close hibernate log out
=ERROR
=ERROR
=WARN
=WARN
=ERROR
=WARN
=ERROR
=WARN
=WARN
=WARN
=WARN
=WARN
=ERROR
=ERROR

Log4j closes Hibernate log output

For project reasons, when using Hibernate, a large number of related logs will always be output, and you want to block them.

After various searches, I found the so-called methods on the Internet:

For example, set in the hibernate configuration file

<!-- Whether to displaysql -->
  <property name="show_sql">false</property>
  <!-- Whether to formatsql -->
  <property name="format_sql">false</property>
  <!-- Whether to use comments -->
  <property name="use_sql_comments">false</property>

Or set it in the log4j configuration file

#log4j for Hibernate
=WARN

None of them works.

The last solution I solved here is: extra settings in the log4j configuration file

#log4j for springMVC
=WARN

It will take effect.

The reason is that the project I am using is annotating and configuring hibernate using spring.

The output of some related logs is mainly based on the spring configuration.

Therefore, the so-called hibernate-based related configurations on the Internet are generally invalid.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.