In springboot integration mybatis development process, Log4j configuration file in order to view the process Mybatis operation of the database
Editor: IDEA
Step: pom.xml introducing dependency (dependency and log4j2 MyBatis dependent)
as follows:
# The spring-boot-starter-web in dependence logging automatically configured, in use need to preclude reliance Log4j
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
# Depend on the introduction of Log4j2
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
Step Two: Log4j configuration .xml file, file location: src / mian / resources (after introduction Log4j dependent, springboot automatically loads Log4j2.xml file)
The basic configuration XML file is as follows:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN" monitorInterval="30"> <Properties> <Property name="LOG_PATTERN"> %d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex </Property> </Properties> <Appenders> <Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true"> <PatternLayout pattern="${LOG_PATTERN}"/> </Console> </Appenders> <Loggers> <Logger name="#{这里填写.mapper包}" level="trace" additivity="false"> <AppenderRef ref="ConsoleAppender" /> </Logger> <Root level="info"> <AppenderRef ref="ConsoleAppender" /> </Root> </Loggers> </Configuration>
In the above <Logger> </ Logger> in Level = "trace", the lowest level Mybatis log is trace, in this log level, Mybatis outputs detailed information about SQL during execution, this level is particularly suitable for use in the development process .
Print Results:
To achieve the above basic configuration, if you want to achieve a log file can be output as a reference address: https://www.callicoder.com/spring-boot-log4j-2-example/
Original Address: https: //blog.csdn.net/U201311105/article/details/85238874