我使用的是springboot1.5java应用程序,并设置了日志级别,以便记录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
但是,我们注意到,当发生异常时,不会显示详细的参数日志(显示哪个参数绑定到哪个值)条目,而是得到异常消息和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"}
我们可以编辑哪些日志级别或设置来显示参数绑定信息,即使在查询执行期间发生错误时也是如此?