Change Spring framework level in a simple project example?

At the following this Spring For example, I expected to see the result as follows:

Creating tables Inserting customer record for John Woo Inserting customer record for Jeff Dean ... 

Instead, I received several DEBUG log messages interspersed between each line:

 Creating tables 12:31:16.474 [main] DEBUG osjdbc.core.JdbcTemplate - Executing SQL statement [drop table customers if exists] 12:31:16.484 [main] DEBUG osjdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource 12:31:16.484 [main] DEBUG osjdSimpleDriverDataSource - Creating new JDBC Driver Connection to [jdbc:h2:mem] ... 

These various answers seem that this can be solved by changing the log level in my log4j.properties file. However, following the Spring example , the log4j.properties file log4j.properties never mentioned.

Interestingly, Spring apparently uses log4j inside:

 $ grep -R "log4j" * Binary file build/libs/gs-relational-data-access-0.1.0.jar matches 

I assume that I could use log4j to fix this problem, but the manual does not seem to contain information on where log4j.properties or how to integrate it into this project.

How to change log level to delete these DEBUG statements?

If I need to use the log4j.properties file, where can I put it? Do I need to bind it to my build.gradle file or refer to it in my .java files somehow?

+6
source share
1 answer

These are Spring Boot works that work with jul , jcl and jcl routing on slf4j and use Logback through slf4j , as you can define using distinguishable shortened namespace class names.

All this is clearly visible through the IntelliJ chart tool directly on the pom file:

enter image description here

This setting is in line with best practice as described / pictured on the SLF4J website :

slf4j bridge setup - login implementation

The magazine is frequent because of the Spring DEBUG level. To change this:

1) Create the resources directory in <projectDir>/src/main , as you would in a Maven project. 2) Create a logback.xml file in it containing:

 <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>web - %date [%thread] %-5level %logger{36} - %message%n </pattern> </encoder> </appender> <logger name="org.springframework" level="WARN" /> <root level="INFO"> <appender-ref ref="STDOUT" /> </root> </configuration> 

and voila!

 Creating tables Inserting customer record for John Woo Inserting customer record for Jeff Dean Inserting customer record for Josh Bloch Inserting customer record for Josh Long Querying for customer records where first_name = 'Josh': Customer[id=3, firstName='Josh', lastName='Bloch'] Customer[id=4, firstName='Josh', lastName='Long'] 
+20
source

Source: https://habr.com/ru/post/958127/


All Articles