logback + log4jdbc-log4j2 输出 jpa sql 参数实际value

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 2SLF4J 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)

效果:

 

[sql] view plain copy

  1. 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   
  2. as name4_2_, user0_.password as password5_2_, user0_.salt as salt6_2_, user0_.status as status7_2_,   
  3. user0_.team_id as team_id8_2_ from ss_user user0_ where user0_.login_name='admin'   
  4.  {executed in 1 msec}  
  5. 17:46:44.383 [qtp79368068-124] INFO  jdbc.resultsettable -   
  6. |---|-------------|-----------|--------------|-----------------------------------------|-----------------|--------|--------|  
  7. |id |email        |login_name |name          |password                                 |salt             |status  |team_id |  
  8. |---|-------------|-----------|--------------|-----------------------------------------|-----------------|--------|--------|  
  9. |1  |admin@cs.com |admin      |administrator |692235df64f14215b1f15ccd79b70b55e63940fa |7awe2safd3b3asdd |enabled |1       |  
  10. |---|-------------|-----------|--------------|-----------------------------------------|-----------------|--------|--------|  


 

 

 

配置:

首先引入依赖jar:

 

[html] view plain copy

  1. <dependency>  
  2.   <groupId>org.bgee.log4jdbc-log4j2</groupId>  
  3.   <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>  
  4.   <version>1.16</version>  
  5. </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文件:

 

[html] view plain copy

  1. <!--log4jdbc -->  
  2. <!--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.-->  
  3. <logger name="jdbc.sqlonly" level="WARN"/>  
  4. <logger name="jdbc.sqltiming" level="INFO"/>  
  5. <logger name="jdbc.resultsettable" level="INFO"/>  
  6. <logger name="jdbc.resultset" level="WARN"/>  
  7. <logger name="jdbc.connection" level="WARN"/>  
  8. <logger name="jdbc.audit" level="WARN"/>  

 

[html] view plain copy

  1.   

 

完成。

转载于:https://my.oschina.net/u/1582930/blog/1634205

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值