The Spring framework is integrated with the logging framework. The logging framework can output some important information in the running process of the Spring framework in the console, which is convenient for us to understand the running process of Spring and helps us to debug
How Spring integrates logging frameworks
-
default
- Spring1,2,3 series were integrated with commons-logging.jar in the early days
- The default integrated logging framework for Spring 4,5 series is logback and log4j2
-
Spring5.x integrated logging framework
-
①Introduce the jar package of log4j
-
②Introduce the log4j.properties configuration file
Import log dependencies in pom.xml
-
<!-- 日志-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
- log4j configuration file
Create log4j.properties under the resources directory
# resources文件夹根目录下
### 配置根
log4j.rootLogger = console , debug
### 日志输出到控制台显示
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n