Mybatis framework | log analysis and use


First, the use of the log in step Mybatis

At first Mybatis program as an example, using Mybatis in log.

Step 1: Create log4j.properties file

Normally this file is placed in the same level and src config folder.
Here Insert Picture Description

Step Two: Write configuration information

# Global logging configuration
log4j.rootLogger=info, stdout
# MyBatis logging configuration...
log4j.logger.org.mybatis.example.BlogMapper=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

About log4j.rootLogger property:

  • When using the on-line real project: log4j.rootLogger = info
  • Test phase: log4j.rootLogger = debug

Second, log analysis

After execution of the first program Mybatis, print out the log is as follows:

DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - Opening JDBC Connection
DEBUG [main] - Created connection 1969003420.
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@755c9b9c]
DEBUG [main] - ==>  Preparing: SELECT id,username as name,sex,address,birthday FROM user WHERE id = ?; 
DEBUG [main] - ==> Parameters: 1(Integer)
DEBUG [main] - <==      Total: 1
1,冬雨,,北京,2020-02-06
DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@755c9b9c]
DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@755c9b9c]
DEBUG [main] - Returned connection 1969003420 to pool.
Log information Log Analysis
Opening JDBC Connection Open the JDBC link
Created connection 1969003420. Create a connection
Setting autocommit to false on JDBC Connection Automatic submission failed transaction
Preparing: SELECT id,username as name,sex,address,birthday FROM user WHERE id = ?; sql statement
Published 394 original articles · won praise 1049 · Views 210,000 +

Guess you like

Origin blog.csdn.net/weixin_43691058/article/details/104221089