From 1e30dd7ce314b791957ca5a2a1ed93baa934b79f Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Sun, 27 Apr 2025 12:20:09 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20SQL=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=BC=82=E5=B8=B8=E6=97=B6=E5=9C=A8=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=B8=AD=E8=BE=93=E5=87=BAsql=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1408610997862400]SQL语句执行异常时在日志中输出sql参数 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1408610997862400 --- .../framework/dao/plugin/ExceptionCatchInterceptor.java | 5 ++++- .../neatlogic/framework/dao/plugin/SqlCostInterceptor.java | 2 +- src/main/java/neatlogic/framework/util/HttpRequestUtil.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/neatlogic/framework/dao/plugin/ExceptionCatchInterceptor.java b/src/main/java/neatlogic/framework/dao/plugin/ExceptionCatchInterceptor.java index 3e70f8383..ccc9294f9 100644 --- a/src/main/java/neatlogic/framework/dao/plugin/ExceptionCatchInterceptor.java +++ b/src/main/java/neatlogic/framework/dao/plugin/ExceptionCatchInterceptor.java @@ -15,6 +15,7 @@ along with this program. If not, see .*/ package neatlogic.framework.dao.plugin; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.cache.CacheKey; @@ -45,7 +46,7 @@ import java.sql.SQLException; @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}) }) public class ExceptionCatchInterceptor implements Interceptor { - + private final static Logger logger = LoggerFactory.getLogger(ExceptionCatchInterceptor.class); @Override public Object intercept(Invocation invocation) throws Throwable { //获取拦截方法的参数 @@ -108,6 +109,8 @@ public class ExceptionCatchInterceptor implements Interceptor { logger.error("parameters: " + JSONObject.toJSONString(parameterObject)); logger.error(targetException.getMessage(), targetException); } + Object parameterObject = invocation.getArgs()[1]; + logger.error("SQL Failed: {} with params: {}", ms.getBoundSql(parameterObject).getSql(), JSON.toJSONString(parameterObject), targetException); throw targetException; } return result; diff --git a/src/main/java/neatlogic/framework/dao/plugin/SqlCostInterceptor.java b/src/main/java/neatlogic/framework/dao/plugin/SqlCostInterceptor.java index 96be1753c..73e6e3ac1 100644 --- a/src/main/java/neatlogic/framework/dao/plugin/SqlCostInterceptor.java +++ b/src/main/java/neatlogic/framework/dao/plugin/SqlCostInterceptor.java @@ -170,7 +170,7 @@ public class SqlCostInterceptor implements Interceptor { if (obj != null) { value = obj.toString(); } else { - value = ""; + value = "NULL"; } } diff --git a/src/main/java/neatlogic/framework/util/HttpRequestUtil.java b/src/main/java/neatlogic/framework/util/HttpRequestUtil.java index 3f1162488..62ffa7296 100644 --- a/src/main/java/neatlogic/framework/util/HttpRequestUtil.java +++ b/src/main/java/neatlogic/framework/util/HttpRequestUtil.java @@ -561,7 +561,7 @@ public class HttpRequestUtil { connection.connect(); return connection; } catch (Exception ex) { - logger.error(ex.getMessage(), ex); + logger.error(this.url + "-" + ex.getMessage(), ex); this.error = ExceptionUtils.getStackTrace(ex); this.errorMsg = ex.getMessage(); } -- Gitee