<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=david@consultants.co.nz" rel="nofollow">David Thexton</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9405?redirect=false" rel="nofollow">SPR-9405</a></strong> and commented</p>
<p dir="auto">I noted when trying to diagnose <a href="https://jira.spring.io/browse/BATCH-1852" rel="nofollow">BATCH-1852</a> (which was making use of JdbcTemplate) that there were no options to enable logging JDBC query parameters or query results.  I recalled this was possible for Hibernate (see <a href="http://www.seamframework.org/Documentation/EnablingJDBCBindParameterLoggingWithHibernateAndLog4j" rel="nofollow">http://www.seamframework.org/Documentation/EnablingJDBCBindParameterLoggingWithHibernateAndLog4j</a>) and wanted the same feature for Spring JdbcTemplate.  I could have used P6Spy (see <a href="http://sourceforge.net/projects/p6spy/" rel="nofollow">http://sourceforge.net/projects/p6spy/</a>), although that approach seemed inconvenient.</p>
<p dir="auto">As this logging can be very verbose I used separate classes (and thus loggers).  Continue to set logger "org.springframework.jdbc.core.JdbcTemplate" to debug to see the queries being executed and simple results.  Additionally set logger "org.springframework.jdbc.core.PreparedStatementValueLogger" to debug for query parameter logging and logger "org.springframework.jdbc.core.PreparedStatementResultLogger" to debug for further query result logging.</p>
<p dir="auto">I've implemented the change in a style that will hopefully be seen to fit and I'll issue a pull request as soon as I've completed testing and committed to my spring-framework fork.  I'm happy to make further changes for this issue if necessary.  Please let me know.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.2 M1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398108982" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12438" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12438/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12438">#12438</a> Logging of SQL Params and Query when using JdbcTemplate (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gupabhi" rel="nofollow">Abhishek Gupta</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7782?redirect=false" rel="nofollow">SPR-7782</a></strong> and commented</p>
<p dir="auto">In production applications it is imperative that SQL statements and bind parameters be logged at a configurable level for support purposes.</p>
<p dir="auto">When using the JdbcTemplate spring does currently log both, but sql statements are logged at debug level and parameters are logged in the 'o.s.j.c.StatementCreatorUtils' class at trace level. It is impractical to keep trace level on in a critical (or any) production system - even for a single class. There are other non-important (or non-functional) debug/trace logs that might be in the class that are not required to be logged. Or new ones might be introduced in future versions.</p>
<p dir="auto">We would want the query/params to be logged at info level but again that might not be suitable for others, so ideally it should be something that is configurable.</p>
<p dir="auto">The work-around today is ugly, in that we wrap the JdbcTemplate just to be able to log the parameters. Ideally, if there could be a property in the JdbcTemplate that accepts the log level for functional logs (query, params in this case) it would be most helpful. Given that JdbcTemplate is now a total replacement for using any low level jdbc api, and is so popular, it makes sense to have this feature that will give users more control and contribute to the completeness of such a widely used Spring offering.</p>
<p dir="auto">I am happy to use any other solution you might have that addresses this use-case.</p>
<p dir="auto">Thanks,<br>
Abhi</p>
<p dir="auto">P.S. This really applies to other classes too like in the jdbc.object package</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398150504" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14041" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14041/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14041">#14041</a> JdbcTemplate parameter and result logging (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398111146" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12774" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12774/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12774">#12774</a> Revisit subsystem-oriented logging</li>
</ul>
<p dir="auto">6 votes, 14 watchers</p>