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

时间:2019-01-17 22:25:33

标签: spring-boot logging jdbctemplate

我正在使用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"}

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

1 个答案:

答案 0 :(得分:0)

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

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