日志中输出 Hibernate HQL 中的参数

0
(0)

需要设置 hibernate 的日志的实现,我这里用slf4j:

public static void main(String[] args) {
    System.setProperty("jboss.logging.provider", "slf4j");
    SpringApplicationBuilder builder = new SpringApplicationBuilder().web(true).sources(Application.class).profiles(
        "web");
    builder.run(args);
}

我用的是spring boot项目结构,所以在application.yml里面直接配置日志:

logging:
  level:
    root: info
    org.hibernate.hql.internal.ast.HqlSqlWalker: error
    org.hibernate.type.descriptor.sql.BasicBinder: trace
#    org.hibernate.type.descriptor.sql.BasicExtractor: trace
    org.hibernate.engine.spi.QueryParameters: trace
#    org.hibernate.engine.query.spi.HQLQueryPlan: trace
    cn.firegod: debug

这样在执行的时候,就会有类似下面这样的输出:

Hibernate: select courseenti0_.id as id1_15_0_, courseenti0_.create_by as create_b2_15_0_, courseenti0_.create_date as create_d3_15_0_, courseenti0_.del_flag as del_flag4_15_0_, courseenti0_.name as name5_15_0_, courseenti0_.remarks as remarks6_15_0_, courseenti0_.update_by as update_b7_15_0_, courseenti0_.update_date as update_d8_15_0_ from cdev_school_course courseenti0_ where courseenti0_.id=?
2018-05-26 13:40:40.523 TRACE 64785 --- [nio-9999-exec-2] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [1]

 

这篇文章有用吗?

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位评论此文章。

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据