logback + log4jdbc-log4j2 输出 jpa sql 参数实际value
2015-06-29 17:33
465 查看
log4jdbc-log4j2是基于log4jdbc开发,是log4jdbc的一个变体。 在result输入格式上做了非常完美的优化。
官网:
https://code.google.com/p/log4jdbc-log4j2/
log4jdbc-log4j2 is a modification of log4jdbc to natively use Log4j 2 (or SLF4J as
usual), that supports JDBC 4.1 to JDBC 3, includes all the improvements of log4jdbc-remix, and provides new improvements on its own. log4jdbc-log4j2:
natively supports Log4j 2. SLF4J can
still be used as usual.
supports JDBC 4.1 (Java 7), JDBC 4 (Java 6), JDBC 3 (Java 5).
includes all the improvements of log4jdbc-remix (can log
result sets as tables, can be configured as a Datasource, can use a plugable SQL formatter).
is available in the sonatype maven repository.
provides new improvements on its own (logging of connection opening execution time, of getGeneratedKeys() queries,
etc)
效果:
配置:
首先引入依赖jar:
1. 设置jdbc driver, 在db.properties中加上:
#log4jdbc-Log4j2 driver
jdbc.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
jdbc.url=jdbc:log4jdbc:h2:file:~/.h2/sswxy_db;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1
2. 在classpath下新增文件 log4jdbc.log4j2.properties ,内容:
# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
3. logback.xml文件:
完成。
官网:
https://code.google.com/p/log4jdbc-log4j2/
log4jdbc-log4j2 is a modification of log4jdbc to natively use Log4j 2 (or SLF4J as
usual), that supports JDBC 4.1 to JDBC 3, includes all the improvements of log4jdbc-remix, and provides new improvements on its own. log4jdbc-log4j2:
natively supports Log4j 2. SLF4J can
still be used as usual.
supports JDBC 4.1 (Java 7), JDBC 4 (Java 6), JDBC 3 (Java 5).
includes all the improvements of log4jdbc-remix (can log
result sets as tables, can be configured as a Datasource, can use a plugable SQL formatter).
is available in the sonatype maven repository.
provides new improvements on its own (logging of connection opening execution time, of getGeneratedKeys() queries,
etc)
效果:
17:46:44.381 [qtp79368068-124] INFO jdbc.sqltiming - select user0_.id as id1_2_, user0_.email as email2_2_, user0_.login_name as login_na3_2_, user0_.name as name4_2_, user0_.password as password5_2_, user0_.salt as salt6_2_, user0_.status as status7_2_, user0_.team_id as team_id8_2_ from ss_user user0_ where user0_.login_name='admin' {executed in 1 msec} 17:46:44.383 [qtp79368068-124] INFO jdbc.resultsettable - |---|-------------|-----------|--------------|-----------------------------------------|-----------------|--------|--------| |id |email |login_name |name |password |salt |status |team_id | |---|-------------|-----------|--------------|-----------------------------------------|-----------------|--------|--------| |1 |admin@cs.com |admin |administrator |692235df64f14215b1f15ccd79b70b55e63940fa |7awe2safd3b3asdd |enabled |1 | |---|-------------|-----------|--------------|-----------------------------------------|-----------------|--------|--------|
配置:
首先引入依赖jar:
<dependency> <groupId>org.bgee.log4jdbc-log4j2</groupId> <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId> <version>1.16</version> </dependency>
1. 设置jdbc driver, 在db.properties中加上:
#log4jdbc-Log4j2 driver
jdbc.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
jdbc.url=jdbc:log4jdbc:h2:file:~/.h2/sswxy_db;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1
2. 在classpath下新增文件 log4jdbc.log4j2.properties ,内容:
# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
3. logback.xml文件:
<!--log4jdbc --> <!--In a typical usage scenario, you might turn on only the jdbc.sqlonly logging at INFO level, just to view the SQL coming out of your program.--> <logger name="jdbc.sqlonly" level="WARN"/> <logger name="jdbc.sqltiming" level="INFO"/> <logger name="jdbc.resultsettable" level="INFO"/> <logger name="jdbc.resultset" level="WARN"/> <logger name="jdbc.connection" level="WARN"/> <logger name="jdbc.audit" level="WARN"/>
完成。
相关文章推荐
- Quick Reference to Patch Numbers for Database PSU, SPU(CPU), Bundle Patches and Patchsets
- Ueeshop:一个移动网站,七大对策,提高转化你值得拥有!
- request 获取各种路径
- NGUI——2个UI叠在一起如何判断手指点击哪个UI
- PyAutoGUI 简介
- 源码解析:ArrayBlockingQueue和LinkedBlockingQueue的区别
- flash builder 4.6在debug调试时需要系统安装flashplayer debug版本
- MyBatis根据Map中key作为字段名,value作为字段值修改数据
- egret笔记之gui内设置动画效果
- mAdapter.notifyDataSetChanged()无法更新UI
- hrml 标签 marquee
- LeetCode_Unique Binary Search Trees II
- 连接字符串中的integrated security=true的意思是什么
- UI隐藏状态栏
- WM_CLOSE WM_QUIT WM_DESTROY 三者的区别
- [iOS]iOS8可用的识别用户方式(IDFA、UUID、IDFV)
- 项目问题总结2:GUID区分大小写吗?
- 循环 创建 UIButton 并添加选中状态 (单选和多选)
- Confluence5.1 最新版的安装&破解&汉化
- IOS图像8之IOS7.0之后UIViewController自定义转场动画