Spring JDBC没有使用log4j记录SQL [英] Spring JDBC is not logging SQL with log4j

查看:101
本文介绍了Spring JDBC没有使用log4j记录SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究弹簧是否可能切换到弹簧组。我认为很酷的一件事是spring jdbc能够记录所有已执行的sql。所以我放入log4j,设置一个log4j.properties文件。没有sql。

I'm researching spring for a possible switch to a spring stack. One of the things that I thought was cool was the ability for spring jdbc to log all the executed sql. So I put in log4j, set up a log4j.properties file. and no sql.

这里是log4j.properties文件:

here is the log4j.properties file:

log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.Patt ernLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout
log4j.category.org.springframework.jdbc.core=DEBUG

这里是一些非常简单的插入的输出sql via spring jdbc: http://pastie.org/713189

here is the output for some really simple insert sql via spring jdbc: http://pastie.org/713189

推荐答案

尝试设置这些额外的 log4j 记录器。第一个将吐出通过spring的 JdbcTemplate 的SQL,第二个将给出Spring在预准备语句上设置的参数值。

Try setting these additional log4j loggers. The first will spit out the SQL that passes through spring's JdbcTemplate, the second gives you parameter values that Spring sets on prepared statements.

<logger name="org.springframework.jdbc.core.JdbcTemplate">
  <level value="debug" />
</logger>

<logger name="org.springframework.jdbc.core.StatementCreatorUtils">
  <level value="debug" />
</logger>

显然,如果您使用<$ c $直接或间接执行SQL,这只会起作用c> JdbcTemplate 。

这篇关于Spring JDBC没有使用log4j记录SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆