飞道的博客

Mybatis框架|日志使用与分析

283人阅读  评论(0)


一、在Mybatis中使用日志的步骤

第一个Mybatis程序为例,介绍Mybatis中日志的使用。

第一步:创建log4j.properties文件

通常情况下此文件放置在和src同级下的config文件夹。

第二步:写入配置信息

# 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

关于log4j.rootLogger属性:

  • 真正的项目上线时使用:log4j.rootLogger=info
  • 测试阶段:log4j.rootLogger=debug

二、日志分析

执行第一个Mybatis程序后,打印出的日志如下:

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.
日志信息 日志分析
Opening JDBC Connection 打开JDBC链接
Created connection 1969003420. 创建连接
Setting autocommit to false on JDBC Connection 事务自动提交失败
Preparing: SELECT id,username as name,sex,address,birthday FROM user WHERE id = ?; sql语句

转载:https://blog.csdn.net/weixin_43691058/article/details/104221089
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场