15 Star 26 Fork 11

JavaRD/log4jdbc-sql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

项目中的SQL语句报错,有时实在不太明显,也没有能够记录执行时间的,所以找到log4jdbc,但是,配置项太多,输出格式不合要求,log4j2集成无法输出日志还是比较头大。今天把源码看了遍,部分地方作了修改。将代码提交此处,方便管理。 log4jdbc项目使用SLF4J 日志,该日志是一个接口,实现有很多种。
本项目中使用log4j2来桥接slf4j的日志,即log4jback的日志了。

#log4jdbc源码 代码基于log4jdbc开源项目

https://code.google.com/archive/p/log4jdbc/ 
https://github.com/arthurblake/log4jdbc   

#log4jdbc概念 可参阅:http://blog.csdn.net/ycpanda/article/details/46519941

#url和driver配置示例 spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF8&characterSetResults=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull

#最佳实践:
###1.log4j.log4jdbc.properties 可以不用
###2.本例配合slf4j+log4j2使用,依赖如下 : pom配置如下:

<slf4j.version>1.7.14</slf4j.version>
<log4j2.version>2.6.2</log4j2.version>

<dependency>
	<groupId>org.slf4j</groupId>
	<artifactId>slf4j-api</artifactId>
	<version>${slf4j.version}</version>
</dependency>
<dependency>
	<groupId>org.apache.logging.log4j</groupId>
	<artifactId>log4j-api</artifactId>
	<version>${log4j2.version}</version>
</dependency>
<dependency>
	<groupId>org.apache.logging.log4j</groupId>
	<artifactId>log4j-core</artifactId>
	<version>${log4j2.version}</version>
</dependency>
<dependency>
	<groupId>org.apache.logging.log4j</groupId>
	<artifactId>log4j-slf4j-impl</artifactId>
	<version>${log4j2.version}</version>
</dependency>

log4j2.xml配置如下 :

<configuration status="WARN" monitorInterval="30" strict="true">
	<Appenders>
		<Console name="Console" target="SYSTEM_OUT" ignoreExceptions="false">
			<PatternLayout pattern="%d{HH:mm:ss.SSS}  %-5level %c{36}- %msg%n" />
		</Console>
	</Appenders>

	<loggers>
	
		<!--log4jdbc -->
		<logger name="jdbc.sqlonly" level="OFF" additivity="false" />
		<logger name="jdbc.resultset" level="OFF" additivity="false" />
		<logger name="jdbc.connection" level="OFF" additivity="false" />
		<logger name="jdbc.audit" level="OFF" additivity="false" />
		<!-- <logger name="log4jdbc.debug" level="INFO" additivity="false" >
			<appender-ref ref="Console" />
		</logger> 
		<logger name="jdbc.sqltiming" level="INFO" additivity="false" >
			<appender-ref ref="Console" />
		</logger>  -->
		
		<!--默认的root的logger -->
		<root level="debug">
			<appender-ref ref="Console" />
		</root>
	</loggers>
</configuration>

###3.相对源码的修改部分 ++ 添加[SQL-CONFIG] 与[SQL] 等特殊字符来明显化这是一条sql操作相关日志

22:09:15.626  DEBUG log4jdbc.debug- [SQL-CONFIG]:  FOUND DRIVER com.mysql.jdbc.Driver

++ 去掉原日志中的回车符号,让日志尽量在一行打印完毕
++ 添加数据库连接信息 (connection:1,e0a1828) ,1为第几个连接,e0a1828为java.sql.Connection对象的hascode的hex值,以此来标示并发时connection的全生命的日志

22:09:17.120  DEBUG jdbc.sqltiming- [SQL]:(connection:5,6f9bc97){update test_curd set name = '更新后的值' where id >= 0 }USE:108ms

###4.实践 #####只打印SQL及执行时间

<root level="debug">或者<root level="info">

#####打印SQL及connection的审计类(ConnectionPreparedStatement)信息

<root level="debug">或者<root level="info">

#####关闭SQL打印

###5.示例日志如下

22:09:15.617  DEBUG log4jdbc.debug- [SQL-CONFIG]:... log4jdbc initializing ...
22:09:15.618  DEBUG log4jdbc.debug- [SQL-CONFIG]:  log4jdbc.properties not found on classpath
22:09:15.618  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.debug.stack.prefix is not defined
22:09:15.618  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.sqltiming.warn.threshold is not defined
22:09:15.618  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.sqltiming.error.threshold is not defined
22:09:15.618  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.booleanastruefalse is not defined (using default value false)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.maxlinelength is not defined (using default of 200)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.fulldebugstacktrace is not defined (using default value false)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.statement.warn is not defined (using default value false)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.select is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.insert is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.update is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.delete is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.create is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.addsemicolon is not defined (using default value false)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.auto.load.popular.drivers is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.trim.sql is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.trim.sql.extrablanklines is not defined (using default value true)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.suppress.generated.keys.exception is not defined (using default value false)
22:09:15.619  DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.drivers is not defined
22:09:15.626  DEBUG log4jdbc.debug- [SQL-CONFIG]:  FOUND DRIVER com.mysql.jdbc.Driver
22:09:15.628  DEBUG log4jdbc.debug- [SQL-CONFIG]:... log4jdbc initialized! ...
22:09:15.785  INFO  jdbc.connection- [SQL]:(connection:1,3aa82b22). Connection opened  java.sql.DriverManager.getConnection(null:-1)
22:09:15.785  DEBUG jdbc.connection- [SQL]:open connections:  1 (1)
22:09:15.785  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.new Connection returned   java.sql.DriverManager.getConnection(null:-1)
22:09:15.798  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.799  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.prepareStatement(drop table if exists test_curd) returned net.sf.log4jdbc.PreparedStatementSpy@7cd569b5  org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.800  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@2b64ff3b  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:15.800  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:1,3aa82b22). drop table if exists test_curd 
22:09:15.990  DEBUG jdbc.sqltiming- [SQL]:(connection:1,3aa82b22){drop table if exists test_curd }USE:190ms
22:09:15.991  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.executeUpdate() returned 0  org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:15.992  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
22:09:15.993  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.993  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.prepareStatement(CREATE TABLE `test_curd` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `create_date` datetime DEFAULT NULL,  `name` varchar(255) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;) returned net.sf.log4jdbc.PreparedStatementSpy@7d380be8  org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.994  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@6a95ec91  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:15.994  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:1,3aa82b22). CREATE TABLE `test_curd` ( `id` int(11) NOT NULL AUTO_INCREMENT, `create_date` datetime DEFAULT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 
22:09:16.741  DEBUG jdbc.sqltiming- [SQL]:(connection:1,3aa82b22){CREATE TABLE `test_curd` ( `id` int(11) NOT NULL AUTO_INCREMENT, `create_date` datetime DEFAULT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; }USE:747ms
22:09:16.742  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.executeUpdate() returned 0  org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:16.742  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
清理表
22:09:16.743  INFO  jdbc.connection- [SQL]:(connection:1,3aa82b22). Connection closed  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.743  DEBUG jdbc.connection- [SQL]:open connections:  none
22:09:16.743  DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)

22:09:16.758  INFO  jdbc.connection- [SQL]:(connection:2,6e9637fe). Connection opened  java.sql.DriverManager.getConnection(null:-1)
22:09:16.758  DEBUG jdbc.connection- [SQL]:open connections:  2 (1)
22:09:16.758  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). Connection.new Connection returned   java.sql.DriverManager.getConnection(null:-1)
22:09:16.761  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.761  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). Connection.prepareStatement(insert into test_curd(name,create_date) values(?,?), 1) returned net.sf.log4jdbc.PreparedStatementSpy@7deb27fa  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.762  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@598dceab  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:16.762  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.setObject(1, 测试中文) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.775  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.setObject(2, Sat Apr 29 22:09:16 CST 2017) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.775  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606) (connection:2,6e9637fe). insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16') 
22:09:16.856  DEBUG jdbc.sqltiming- [SQL]:(connection:2,6e9637fe){insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16') }USE:80ms
22:09:16.856  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.executeUpdate() returned 1  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606)
22:09:16.871  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.872  DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.new ResultSet returned   org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.872  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getGeneratedKeys() returned net.sf.log4jdbc.ResultSetSpy@2e28dfb2  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.873  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617  org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.873  DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.next() returned true  org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.876  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.877  DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@3c1a42fa - Field level information: 
	com.mysql.jdbc.Field@602349e9[catalog=null,tableName=,originalTableName=null,columnName=GENERATED_KEY,originalColumnName=null,mysqlType=-1( Unknown MySQL Type # -1),flags=, charsetIndex=0, charsetName=UTF8]  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.878  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.878  DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.getObject(1) returned 1  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.879  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
insertTest: {GENERATED_KEY=1}
insertTest: null
22:09:16.881  INFO  jdbc.connection- [SQL]:(connection:2,6e9637fe). Connection closed  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.881  DEBUG jdbc.connection- [SQL]:open connections:  none
22:09:16.882  DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). Connection.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)

22:09:16.905  INFO  jdbc.connection- [SQL]:(connection:3,454d427a). Connection opened  java.sql.DriverManager.getConnection(null:-1)
22:09:16.905  DEBUG jdbc.connection- [SQL]:open connections:  3 (1)
22:09:16.905  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). Connection.new Connection returned   java.sql.DriverManager.getConnection(null:-1)
22:09:16.906  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.906  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). Connection.prepareStatement(insert into test_curd(name,create_date) values(?,?), 1) returned net.sf.log4jdbc.PreparedStatementSpy@79e4de3d  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.906  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@20bab550  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:16.906  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.setObject(1, 测试中文) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.907  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.setObject(2, Sat Apr 29 22:09:16 CST 2017) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.907  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606) (connection:3,454d427a). insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16') 
22:09:16.986  DEBUG jdbc.sqltiming- [SQL]:(connection:3,454d427a){insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16') }USE:79ms
22:09:16.987  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.executeUpdate() returned 1  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606)
22:09:16.987  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.987  DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.new ResultSet returned   org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.987  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getGeneratedKeys() returned net.sf.log4jdbc.ResultSetSpy@65006fed  org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.987  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33  org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.988  DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.next() returned true  org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.988  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.988  DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@7fb46468 - Field level information: 
	com.mysql.jdbc.Field@1c2c2958[catalog=null,tableName=,originalTableName=null,columnName=GENERATED_KEY,originalColumnName=null,mysqlType=-1( Unknown MySQL Type # -1),flags=, charsetIndex=0, charsetName=UTF8]  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.988  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.988  DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.getObject(1) returned 2  org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.988  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
insertTest: {GENERATED_KEY=2}
insertTest: null
22:09:16.988  INFO  jdbc.connection- [SQL]:(connection:3,454d427a). Connection closed  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.988  DEBUG jdbc.connection- [SQL]:open connections:  none
22:09:16.988  DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). Connection.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)

22:09:16.998  INFO  jdbc.connection- [SQL]:(connection:4,3bf06804). Connection opened  java.sql.DriverManager.getConnection(null:-1)
22:09:16.998  DEBUG jdbc.connection- [SQL]:open connections:  4 (1)
22:09:16.998  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). Connection.new Connection returned   java.sql.DriverManager.getConnection(null:-1)
22:09:16.998  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:16.999  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). Connection.prepareStatement(select * from test_curd where id>?) returned net.sf.log4jdbc.PreparedStatementSpy@201d324c  org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:16.999  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@5cd12c0c  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:16.999  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.setObject(1, 1) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.999  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347) (connection:4,3bf06804). select * from test_curd where id>1 
22:09:16.999  DEBUG jdbc.sqltiming- [SQL]:(connection:4,3bf06804){select * from test_curd where id>1 }USE:0ms
22:09:16.999  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
22:09:16.999  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.new ResultSet returned   org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
22:09:17.000  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.executeQuery() returned net.sf.log4jdbc.ResultSetSpy@6322ad40  org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
22:09:17.000  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.handlers.ArrayHandler.handle(ArrayHandler.java:83)
22:09:17.000  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.next() returned true  org.apache.commons.dbutils.handlers.ArrayHandler.handle(ArrayHandler.java:83)
22:09:17.000  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:99)
22:09:17.000  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@799c7798 - Field level information: 
	com.mysql.jdbc.Field@f6fda88[catalog=test,tableName=test_curd,originalTableName=test_curd,columnName=id,originalColumnName=id,mysqlType=3(FIELD_TYPE_LONG),flags= AUTO_INCREMENT PRIMARY_KEY, charsetIndex=63, charsetName=US-ASCII]
	com.mysql.jdbc.Field@78741ea2[catalog=test,tableName=test_curd,originalTableName=test_curd,columnName=create_date,originalColumnName=create_date,mysqlType=12(FIELD_TYPE_DATETIME),flags= BINARY, charsetIndex=63, charsetName=US-ASCII]
	com.mysql.jdbc.Field@f875b76[catalog=test,tableName=test_curd,originalTableName=test_curd,columnName=name,originalColumnName=name,mysqlType=253(FIELD_TYPE_VAR_STRING),flags=, charsetIndex=33, charsetName=UTF-8]  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:99)
22:09:17.000  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getObject(1) returned 2  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getObject(2) returned 2017-04-29 22:09:16.0  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.001  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getObject(3) returned 测试中文  org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.001  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:72)
22:09:17.001  DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:72)
22:09:17.001  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
selectTest: [2, 2017-04-29 22:09:16.0, 测试中文]
22:09:17.001  INFO  jdbc.connection- [SQL]:(connection:4,3bf06804). Connection closed  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.001  DEBUG jdbc.connection- [SQL]:open connections:  none
22:09:17.001  DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). Connection.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)

22:09:17.011  INFO  jdbc.connection- [SQL]:(connection:5,6f9bc97). Connection opened  java.sql.DriverManager.getConnection(null:-1)
22:09:17.011  DEBUG jdbc.connection- [SQL]:open connections:  5 (1)
22:09:17.011  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). Connection.new Connection returned   java.sql.DriverManager.getConnection(null:-1)
22:09:17.011  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.011  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). Connection.prepareStatement(update test_curd set name = ? where id >= ?) returned net.sf.log4jdbc.PreparedStatementSpy@3cf9a477  org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.012  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@299c9fe7  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:17.012  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.setObject(1, 更新后的值) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:17.012  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.setObject(2, 0) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:17.012  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:5,6f9bc97). update test_curd set name = '更新后的值' where id >= 0 
22:09:17.120  DEBUG jdbc.sqltiming- [SQL]:(connection:5,6f9bc97){update test_curd set name = '更新后的值' where id >= 0 }USE:108ms
22:09:17.120  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.executeUpdate() returned 2  org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:17.121  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
成功更新2条数据!
22:09:17.122  INFO  jdbc.connection- [SQL]:(connection:5,6f9bc97). Connection closed  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.122  DEBUG jdbc.connection- [SQL]:open connections:  none
22:09:17.122  DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). Connection.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)

22:09:17.163  INFO  jdbc.connection- [SQL]:(connection:6,85132f5). Connection opened  java.sql.DriverManager.getConnection(null:-1)
22:09:17.163  DEBUG jdbc.connection- [SQL]:open connections:  6 (1)
22:09:17.164  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). Connection.new Connection returned   java.sql.DriverManager.getConnection(null:-1)
22:09:17.164  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.new PreparedStatement returned   org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.164  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). Connection.prepareStatement(DELETE from test_curd WHERE id = ?) returned net.sf.log4jdbc.PreparedStatementSpy@23e28c99  org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.164  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@6e7ca336  org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:17.165  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.setObject(1, 0) returned   org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:17.165  DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:6,85132f5). DELETE from test_curd WHERE id = 0 
22:09:17.166  DEBUG jdbc.sqltiming- [SQL]:(connection:6,85132f5){DELETE from test_curd WHERE id = 0 }USE:0ms
22:09:17.166  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.executeUpdate() returned 0  org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:17.166  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
删除成功0条数据!
22:09:17.167  INFO  jdbc.connection- [SQL]:(connection:6,85132f5). Connection closed  org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.167  DEBUG jdbc.connection- [SQL]:open connections:  none
22:09:17.167  DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). Connection.close() returned   org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

log4jdbc的部分定制与研究 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/javard/log4jdbc-sql.git
git@gitee.com:javard/log4jdbc-sql.git
javard
log4jdbc-sql
log4jdbc-sql
master

搜索帮助