Skip to content

Logging of SQL Params and Query when using JdbcTemplate [SPR-7782] #12438

@spring-projects-issues

Description

@spring-projects-issues

Abhishek Gupta opened SPR-7782 and commented

In production applications it is imperative that SQL statements and bind parameters be logged at a configurable level for support purposes.

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.

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.

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.

I am happy to use any other solution you might have that addresses this use-case.

Thanks,
Abhi

P.S. This really applies to other classes too like in the jdbc.object package


Affects: 3.0.5

Issue Links:

6 votes, 14 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions