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

问题描述 投票:0回答:1

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

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

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"}

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

spring-boot logging jdbctemplate
1个回答
0
投票

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

org.springframework.jdbc.core.JdbcTemplate: DEBUG #log sql queries
org.springframework.jdbc.core.StatementCreatorUtils: TRACE #Log sql parameter values
© www.soinside.com 2019 - 2024. All rights reserved.