Mybatis learning 3______ use log4j print log information

(In this case project done in maven test :)

1. leader packet: in pom.xml

        <!-- log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

2. log4j.properties file is carried out under the src / resources to write:

### Log4j configuration ### 
### and Spring combined with the need to specify the file location in web.xml, and add listeners ### 
output level and the output destination #define log4j (destination can customize the name, and the following correspondence) 
# [Level], appenderName1, appenderName2 
Log4j.rootLogger = the DEBUG, Console, File 

# --------------------------- # -------- 
# 1 is defined as the destination of the log output console 
log4j.appender.console = org.apache.log4j.ConsoleAppender tells that 
log4j.appender.console.Target = the System.out 
log4j.appender.console.Threshold the DEBUG = 
#### log flexibility to specify the output format, the following line is designated specific format ### 
# C%: category output log information belongs, is usually the full name of the class where 
#% m: output code specified message, the generated specific information log 
#% n: output a carriage return linefeed, Windows platform "/ r / n", Unix platform "/ n" output log information wrap 
log4j.appender.console.layout = org .apache.log4j.PatternLayout 
log4j.appender.console.layout.ConversionPattern = [% C] -% m% n-

# # ----------------------------------- 
time # 2 file size reaches the specified size to generate a new file 
log4j.appender.file = org.apache.log4j.RollingFileAppender 
# log file output directory 
log4j.appender.file.File = log / tibet.log 
# define the maximum file size 
log4j.appender.file.MaxFileSize = 10MB 
### output log ### 
# lowest level 
log4j.appender.file.Threshold = ERROR 
log4j.appender.file.layout = Org.apache.log4j.PatternLayout 
log4j.appender.file.layout.ConversionPattern = [P%] [% {D the MM-dd}-YY] [% C]% m% n- 

# ---------------------------------- - # 
#. 3 Druid 
log4j.logger.druid.sql the iNFO = 
log4j.logger.druid.sql.DataSource = info 
log4j.logger.druid.sql.Connection = info  
log4j.logger.druid.sql.Statement info =
log4j.logger.druid.sql.ResultSet info =

#4 mybatis 显示SQL语句部分
log4j.logger.org.mybatis=DEBUG
#log4j.logger.cn.tibet.cas.dao=DEBUG
#log4j.logger.org.mybatis.common.jdbc.SimpleDataSource=DEBUG
#log4j.logger.org.mybatis.common.jdbc.ScriptRunner=DEBUG
#log4j.logger.org.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
#log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

Configure 3.mybatis core file:

  < Settings > 
        < Setting name = "logImpl" value = "LOG4J" /> 
    </ Settings > 
 
(prepared note configuration parameter sequence)

A test output log follows:

[org.apache.ibatis.logging.LogFactory]-Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
[org.apache.ibatis.logging.LogFactory]-Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter.
[org.apache.ibatis.io.VFS]-Class not found: org.jboss.vfs.VFS
[org.apache.ibatis.io.JBoss6VFS]-JBoss 6 VFS API is not available in this environment.
[org.apache.ibatis.io.VFS]-Class not found: org.jboss.vfs.VirtualFile
[org.apache.ibatis.io.VFS]-VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.
[org.apache.ibatis.io.VFS]-Using VFS adapter org.apache.ibatis.io.DefaultVFS
[org.apache.ibatis.io.DefaultVFS]-Find JAR URL: file:/E:/IdeaProjects/Mybatis_7_24_zhujie/target/classes/com/xbf/pojo
[org.apache.ibatis.io.DefaultVFS]-Not a JAR: file:/E:/IdeaProjects/Mybatis_7_24_zhujie/target/classes/com/xbf/pojo
[org.apache.ibatis.io.DefaultVFS]-Reader entry: User.class
[org.apache.ibatis.io.DefaultVFS]-Listing file:/E:/IdeaProjects/Mybatis_7_24_zhujie/target/classes/com/xbf/pojo
[org.apache.ibatis.io.DefaultVFS]-Find JAR URL: file:/E:/IdeaProjects/Mybatis_7_24_zhujie/target/classes/com/xbf/pojo/User.class
[org.apache.ibatis.io.DefaultVFS]-Not a JAR: file:/E:/IdeaProjects/Mybatis_7_24_zhujie/target/classes/com/xbf/pojo/User.class
[org.apache.ibatis.io.DefaultVFS]-Reader entry: ����   1 <
[org.apache.ibatis.io.ResolverUtil]-Checking to see if class com.xbf.pojo.User matches criteria [is assignable to Object]
[org.apache.ibatis.datasource.pooled.PooledDataSource]-PooledDataSource forcefully closed/removed all connections.
[org.apache.ibatis.datasource.pooled.PooledDataSource]-PooledDataSource forcefully closed/removed all connections.
[org.apache.ibatis.datasource.pooled.PooledDataSource]-PooledDataSource forcefully closed/removed all connections.
[org.apache.ibatis.datasource.pooled.PooledDataSource]-PooledDataSource forcefully closed/removed all connections.
[org.apache.ibatis.transaction.jdbc.JdbcTransaction]-Opening JDBC Connection
[org.apache.ibatis.datasource.pooled.PooledDataSource]-Created connection 996796369.
[com.xbf.dao.UserMapper.getAllUser]-==>  Preparing: select * from user 
[com.xbf.dao.UserMapper.getAllUser]-==> Parameters: 
[com.xbf.dao.UserMapper.getAllUser]-<==      Total: 5
[User{id=1, name='狂神', pwd='123456'}, User{id=2, name='老七', pwd='250'}, User{id=3, name='李四', pwd='987654'}, User{id=4, name='张三', pwd='250'}, User{id=5, name='老五', pwd='666'}]
[org.apache.ibatis.transaction.jdbc.JdbcTransaction]-Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@3b69e7d1]
[org.apache.ibatis.datasource.pooled.PooledDataSource]-Returned connection 996796369 to pool.

Process finished with exit code 0

 

Guess you like

Origin www.cnblogs.com/xbfchder/p/11237297.html