mybatis的两种日志

四、日志

setting设置:logImpl(key) :

  • SLF4J
  • LOG4J
  • LOG4J2
  • JDK_LOGGING
  • COMMONS_LOGGING
  • STDOUT_LOGGING
  • NO_LOGGING
    由于太多,我就简单介绍和配置一下我自己使用的日志;

第一种STDOUT_LOGGING

<settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>

日志输出:

Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
Class not found: org.jboss.vfs.VFS
JBoss 6 VFS API is not available in this environment.
Class not found: org.jboss.vfs.VirtualFile
VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.
Using VFS adapter org.apache.ibatis.io.DefaultVFS
Find JAR URL: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/test-classes/com/saxon/Dao
Not a JAR: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/test-classes/com/saxon/Dao
Reader entry: UserDaoTest.class
Listing file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/test-classes/com/saxon/Dao
Find JAR URL: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/test-classes/com/saxon/Dao/UserDaoTest.class
Not a JAR: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/test-classes/com/saxon/Dao/UserDaoTest.class
Reader entry: ����   5 �
Find JAR URL: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao
Not a JAR: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao
Reader entry: UserMapper.class
Reader entry: UserMapper.xml
Listing file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao
Find JAR URL: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao/UserMapper.class
Not a JAR: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao/UserMapper.class
Reader entry: ����   5    getUserList ()Ljava/util/List; 	Signature )()Ljava/util/List<Lcom/saxon/pojo/User;>; 	getUserID (I)Lcom/saxon/pojo/User; 
Find JAR URL: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao/UserMapper.xml
Not a JAR: file:/D:/IDEAL项目/Saxon_Mybatis/mybatis_01/target/classes/com/saxon/Dao/UserMapper.xml
Reader entry: <?xml version="1.0" encoding="UTF-8"?>
Checking to see if class com.saxon.Dao.UserDaoTest matches criteria [is assignable to Object]
Checking to see if class com.saxon.Dao.UserMapper matches criteria [is assignable to Object]
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory@1e1a0406
Opening JDBC Connection
Created connection 220695851.
Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@d278d2b]
==>  Preparing: select * from mybatis.saxon
==> Parameters: 
<==    Columns: id, user, pwd
<==        Row: 1, saxon, 1234567
<==        Row: 2, saxon, 441564161
<==      Total: 2
441564161
[User{id=1, user='saxon', pwd='1234567'}, User{id=2, user='saxon', pwd='441564161'}]
Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@d278d2b]
Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@d278d2b]
Returned connection 220695851 to pool.

Process finished with exit code 0

重要信息:

Opening JDBC Connection
Created connection 220695851.
Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@d278d2b]
==>  Preparing: select * from mybatis.saxon
==> Parameters: 
<==    Columns: id, user, pwd
<==        Row: 1, saxon, 1234567
<==        Row: 2, saxon, 441564161
<==      Total: 2
441564161
[User{id=1, user='saxon', pwd='1234567'}, User{id=2, user='saxon', pwd='441564161'}]
Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@d278d2b]
Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@d278d2b]
Returned connection 220695851 to pool.

第二种:LOG4J

1.先导入包

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

2.setting设置

#将等级为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/saxon.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.appender.file.Append=false

#日志输出级别
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.测试

import org.apache.log4j.Logger;
static Logger logger = Logger.getLogger (UserDaoTest.class);
@Test
 public  void  testLog4j(){
        logger.info ("我是谁");
        logger.error ("我是谁");
        logger.debug ("我是谁");
}

其他的日志我也不会,慢慢学习中;
自学地址:狂神说Java

上一篇:Shopify如何选品中文教程 – 跨境电商的八种商业机会类型


下一篇:java-关于使用Saxon使用默认名称空间对xml进行xpath解析