发生错误时显示 sql 查询的参数详细信息

Show parameter details of sql query when an error occurs

我正在使用 spring boot 1.5 java 应用程序并设置了日志级别以便 JDBC(使用 spring 的 jdbctemplate)sql 查询及其参数被记录。我们连接的数据库是Sybase v15.

logging:
  file: /app/logs/${spring.application.name}.log
  max-history: 10
  level:
    root: INFO
    org.springframework: INFO
    org.springframework.jdbc: DEBUG

然而,我们注意到当异常发生时,详细的参数日志(显示哪个参数绑定到哪个值)条目没有显示,而是我们得到异常消息和堆栈跟踪。这使得很难确切知道是哪个字段导致了问题。例如,以下消息确实需要参数信息才能了解导致问题的原因:

UserRepositoryClient#updateUser(Long,User); content:
{"timestamp":"2019-01-17T09:05:18Z","status":500,"error":"Internal Server Error","exception":"org.springframework.dao.TransientDataAccessResourceException","message":"PreparedStatementCallback; SQL [INSERT INTO myTable VALUES(     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?)]; Scale error during implicit conversion of DECIMAL value '0.1' to a INT field.\n; nested exception is java.sql.SQLException: Scale error during implicit conversion of DECIMAL value '0.1' to a INT field.\n","path":"/quotes/94379095"}

我们可以编辑哪些日志级别或设置来显示参数绑定信息,即使在查询执行期间发生错误时也是如此?

我们找到的正确日志级别是:

org.springframework.jdbc.core.JdbcTemplate: DEBUG #log sql queries
org.springframework.jdbc.core.StatementCreatorUtils: TRACE #Log sql parameter values