kookob / plugin

Intellij Plugin Document.
https://plugins.jetbrains.com/organization/abc
Other
3 stars 3 forks source link

启动 IDEA 后,再启动 Spring 正常工作,但是打印了十几个 SQL 后就不打印了 #7

Closed tianyu94 closed 2 years ago

tianyu94 commented 2 years ago

IDE:

IntelliJ IDEA 2022.1 (Ultimate Edition)
Build #IU-221.5080.210, built on April 12, 2022
Licensed to ***
Subscription is active until February 14, 2023.
Runtime version: 11.0.14.1+1-b2043.25 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 8192M
Cores: 12
Registry:
    eslint.additional.file.extensions=svelte

Non-Bundled Plugins:
    String Manipulation (9.4.0)
    com.majera.intellij.codereview.gitlab (2022.1.1.221)
    CheckStyle-IDEA (5.64.0)
    MavenRunHelper (4.20.213.3714.1)
    org.jetbrains.plugins.vue (221.5080.169)
    io.k6.ide.plugin (0.3.0)
    com.obroom.plugin.jpasql (2022.4.2)
    zielu.gittoolbox (212.8.9)
    com.intellij.bigdatatools (221.4165.63)
    com.haulmont.jpab (2022.2.1-221)
2022-04-22 17:32:53.603 DEBUG 1708 --- [nio-8030-exec-7] org.hibernate.SQL                        : select aiccphonen0_.id as id1_22_0_, aiccphonen0_.created_by as created10_22_0_, aiccphonen0_.created_date as created_2_22_0_, aiccphonen0_.last_modified_by as last_mo11_22_0_, aiccphonen0_.last_modified_date as last_mod3_22_0_, aiccphonen0_.version as version4_22_0_, aiccphonen0_.sys_tenant_id as sys_ten12_22_0_, aiccphonen0_.enabled as enabled5_22_0_, aiccphonen0_.full_name as full_nam6_22_0_, aiccphonen0_.person_info_id as person_13_22_0_, aiccphonen0_.phone_number as phone_nu7_22_0_, aiccphonen0_.phone_number_group_id as phone_n14_22_0_, aiccphonen0_.remark as remark8_22_0_, aiccphonen0_.variable as variable9_22_0_ from xxx_phone_number aiccphonen0_ where aiccphonen0_.id=?
2022-04-22 17:32:53.627 TRACE 1708 --- [nio-8030-exec-7] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [BIGINT] - [966252262575837184]

比如这个,我用 Text 标签的功能倒是可以,

我的配置:

preparing:

org.hibernate.SQL                        :

parameters: binding parameter

kookob commented 2 years ago

左边rerun按钮点一下试试

tianyu94 commented 2 years ago

试过的,重启应用也不行,必须重启ide,但是还是会出现这个问题。最开始我用了grep console 插件,那个时候都不行,卸载后就可以了,但是就出现这个情况了。有方法开启插件的日志么,我给你日志分析

在 2022年4月22日,17:58,ob @.***> 写道:

 左边rerun按钮点一下试试

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

kookob commented 2 years ago

出问题的时候grep console这个开启吗?感觉可能会互相影响到,你先关掉试下。。

tianyu94 commented 2 years ago

就是关了的,也卸载了的,卸载后也有问题

在 2022年4月22日,18:13,ob @.***> 写道:

 出问题的时候grep console这个开启吗?感觉可能会互相影响到,你先关掉试下。。

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

kookob commented 2 years ago

这暂时有点没头绪,你打印不出来的时,帮忙把控制台的日志贴一下。插件是否最新版本的?

tianyu94 commented 2 years ago
2022-04-24 08:55:38.582 DEBUG 23840 --- [nio-8030-exec-1] org.hibernate.SQL                        : select cast(sum(cast(case when aiccmsginf0_.state in (? , ?) then ? else ? end as signed)) as signed) as col_0_0_ from aicc_msg_info_record aiccmsginf0_ where aiccmsginf0_.created_date>? and aiccmsginf0_.created_date<? and aiccmsginf0_.sys_tenant_id=?
2022-04-24 08:55:38.582 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [4]
2022-04-24 08:55:38.582 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [INTEGER] - [2]
2022-04-24 08:55:38.582 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [3] as [INTEGER] - [1]
2022-04-24 08:55:38.582 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [4] as [INTEGER] - [0]
2022-04-24 08:55:38.583 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [5] as [TIMESTAMP] - [2022-04-23T00:00]
2022-04-24 08:55:38.583 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [6] as [TIMESTAMP] - [2022-04-23T23:59:59]
2022-04-24 08:55:38.584 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [7] as [BIGINT] - [928929552363687936]

最新的,而且有个问题,我是最新的 SpringBoot 2.6.6,这个配置 show-sql: true 似乎不起作用,我是通过 org.hibernate.SQL: debug 将原始 SQL 打印出来的,JPA SQL 插件的 Preparing 配置是

org.hibernate.SQL                        :
kookob commented 2 years ago

在插件的settings里面配置,你看下Preparing,把默认的改成你的前缀上面的前缀试下。 image

tianyu94 commented 2 years ago

image

tianyu94 commented 2 years ago

是这样的,刚才又是打印到 20 个 SQL 就没打印了

kookob commented 2 years ago

能打印的20个SQL也是上面的前缀吗?

kookob commented 2 years ago

我改成org.hibernate.SQL :是可以打印了。

kookob commented 2 years ago

你查下sql日志的前缀有没有变化

tianyu94 commented 2 years ago

debug.log

日志较多,你看下这个吧,重启 IDE 再启动应用,分别是 Spring 的日志和 JPA SQL 的。

出现这种情况后,我只有重启 IDE 后能打印一部分格式化SQL,重启前点那个 rerun 也不行

文件应该是 md 格式的,改错了

kookob commented 2 years ago

谢谢,过后我排查下

kookob commented 2 years ago

大概原因知道了,从后面开始,你代码里面有多线程的日志输出,导致解析混乱出错了。 这个解决起来会麻烦些。

tianyu94 commented 2 years ago

应该不存在完全同步的系统吧,多个请求时肯定会出现并发。

解析 SQL 语句的时候,通过正则匹配一个 query 或 update

比如配置为正则:

.*([.*]) org.hibernate.SQL                        :

相关的日志通过 Matcher group 进行关联,比如这种情况可以根据线程名称作为关联的key,如其他的情况也可以自己配置多个 group,反正组合一起的就当做一个查询(select + parameters)

log示例:

2022-04-24 08:55:38.582 DEBUG 23840 --- [nio-8030-exec-1] org.hibernate.SQL                        : select cast(sum(cast(case when aiccmsginf0_.state in (? , ?) then ? else ? end as signed)) as signed) as col_0_0_ from aicc_msg_info_record aiccmsginf0_ where aiccmsginf0_.created_date>? and aiccmsginf0_.created_date<? and aiccmsginf0_.sys_tenant_id=?
2022-04-24 08:55:38.582 TRACE 23840 --- [nio-8030-exec-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [4]

第1行匹配出: nio-8030-exec-1, select ... 第2行匹配出: nio-8030-exec-1, [1] as [INTEGER] - [4]

然后根据匹配的 group 分发给独立的解析器,这样每个线程的日志顺序肯定能保证,然后并发下也不会受到其他线程输出的干扰

kookob commented 2 years ago

嗯,跟我的想法一样,下个版本会解决。

kookob commented 2 years ago

@tianyu94 最新版本已经可以更新,再试下看看: https://plugins.jetbrains.com/plugin/15242-jpa-sql/versions

tianyu94 commented 2 years ago

可以了,厉害了我的bro,你是我的神