栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mybatis-06:mybatis配置文件属性Setting之日志

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mybatis-06:mybatis配置文件属性Setting之日志

日志

日志是什么

1、STDOUT_LOGGING2、log4j 想要自定义输出日志

日志是什么

1、STDOUT_LOGGING

    

他会把里面一些关键的信息输出在我们的控制台
比如jdbc连接,执行的sql,参数,结果,关闭连接

2、log4j

1、导入log4j依赖

    
    
    
      log4j
      log4j
      1.2.17
    

2、写一个配置文件log4j.properties(通过配置文件灵活配置)

#将等级为DEBUG的日志信息输出到console(控制台)和file(文件)这两个目的地,console和file的定义在下面的代码
log4j.rootLogger=DEBUG,console,file

#控制台输出的相关设置
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%c]-%m%n

#文件输出的相关设置
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./log/liu.log
log4j.appender.file.MaxFileSize=10mb
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

#日志输出级别
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

3、配置log4j为日志的实现


    

4、测试数据库查询日志会输出到一个文件里面和控制台里面

[DEBUG][22-03-20][org.apache.ibatis.logging.LogFactory]Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
[DEBUG][22-03-20][org.apache.ibatis.logging.LogFactory]Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
[DEBUG][22-03-20][org.apache.ibatis.io.VFS]Class not found: org.jboss.vfs.VFS
[DEBUG][22-03-20][org.apache.ibatis.io.JBoss6VFS]JBoss 6 VFS API is not available in this environment.
[DEBUG][22-03-20][org.apache.ibatis.io.VFS]Class not found: org.jboss.vfs.VirtualFile
[DEBUG][22-03-20][org.apache.ibatis.io.VFS]VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.
[DEBUG][22-03-20][org.apache.ibatis.io.VFS]Using VFS adapter org.apache.ibatis.io.DefaultVFS
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Find JAR URL: file:/F:/idea%20project/mybatis-study/mybatis-03/target/classes/com/liu/pojo
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Not a JAR: file:/F:/idea%20project/mybatis-study/mybatis-03/target/classes/com/liu/pojo
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Reader entry: User.class
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Listing file:/F:/idea%20project/mybatis-study/mybatis-03/target/classes/com/liu/pojo
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Find JAR URL: file:/F:/idea%20project/mybatis-study/mybatis-03/target/classes/com/liu/pojo/User.class
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Not a JAR: file:/F:/idea%20project/mybatis-study/mybatis-03/target/classes/com/liu/pojo/User.class
[DEBUG][22-03-20][org.apache.ibatis.io.DefaultVFS]Reader entry: ����   4 @
[DEBUG][22-03-20][org.apache.ibatis.io.ResolverUtil]Checking to see if class com.liu.pojo.User matches criteria [is assignable to Object]
[DEBUG][22-03-20][org.apache.ibatis.datasource.pooled.PooledDataSource]PooledDataSource forcefully closed/removed all connections.
[DEBUG][22-03-20][org.apache.ibatis.datasource.pooled.PooledDataSource]PooledDataSource forcefully closed/removed all connections.
[DEBUG][22-03-20][org.apache.ibatis.datasource.pooled.PooledDataSource]PooledDataSource forcefully closed/removed all connections.
[DEBUG][22-03-20][org.apache.ibatis.datasource.pooled.PooledDataSource]PooledDataSource forcefully closed/removed all connections.
[DEBUG][22-03-20][org.apache.ibatis.transaction.jdbc.JdbcTransaction]Opening JDBC Connection
[DEBUG][22-03-20][org.apache.ibatis.datasource.pooled.PooledDataSource]Created connection 1403704789.
[DEBUG][22-03-20][org.apache.ibatis.transaction.jdbc.JdbcTransaction]Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@53aad5d5]
[DEBUG][22-03-20][com.liu.mapper.UserMapper.selectUserById]==>  Preparing: select * from user where id=?
[DEBUG][22-03-20][com.liu.mapper.UserMapper.selectUserById]==> Parameters: 7(Integer)
[DEBUG][22-03-20][com.liu.mapper.UserMapper.selectUserById]<==      Total: 1
[DEBUG][22-03-20][org.apache.ibatis.transaction.jdbc.JdbcTransaction]Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@53aad5d5]
[DEBUG][22-03-20][org.apache.ibatis.transaction.jdbc.JdbcTransaction]Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@53aad5d5]
[DEBUG][22-03-20][org.apache.ibatis.datasource.pooled.PooledDataSource]Returned connection 1403704789 to pool.
想要自定义输出日志

1、在类里面导入log4j的包

import org.apache.log4j.Logger;

2、创建logger对象,参数为当前类的calss

Logger logger = Logger.getLogger(UserDaoTest.class);

*3、自定义输出日志(三种级别)

logger.info("info");
logger.debug("debug");
logger.error("error");

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/775557.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号