From e92528e029e6fe487211b240687e379510a27056 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 10 Oct 2025 17:58:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=BC=82=E5=B8=B8=E6=97=B6=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1529025481113600]访问接口异常时,在打印日志时增加接口入参信息 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1529025481113600 --- .../threadlocal/RequestContext.java | 16 ++------- .../converter/RequestParamConverter.java | 36 +++++++++++++++++++ .../login/handler/LoginController.java | 3 +- .../handler/AnonymousApiDispatcher.java | 2 +- .../dispatch/handler/ApiDispatcher.java | 5 ++- .../dispatch/handler/PublicApiDispatcher.java | 4 ++- 6 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 src/main/java/neatlogic/framework/logback/converter/RequestParamConverter.java diff --git a/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java b/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java index 413c43e3b..d3aeffcd6 100644 --- a/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java +++ b/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java @@ -74,17 +74,7 @@ public class RequestContext implements Serializable { public void setParam(String param) { this.param = param; - String tempUrl = StringUtils.EMPTY; - if (StringUtils.isNotBlank(this.url)) { - tempUrl = this.url; - } - if (StringUtils.isNotBlank(this.remoteAddr)) { - tempUrl += "(" + this.remoteAddr + ")"; - } - if (StringUtils.isNotBlank(this.param)) { - tempUrl += "(param=" + this.param + ")"; - } - MDC.put("url", tempUrl); + MDC.put("param", this.param); } public HttpServletRequest getRequest() { @@ -180,11 +170,11 @@ public class RequestContext implements Serializable { if (StringUtils.isNotBlank(remoteAddr)) { tempUrl += "(" + remoteAddr + ")"; } + MDC.put("url", tempUrl); String param = _requestContext.getParam(); if (StringUtils.isNotBlank(param)) { - tempUrl += "(param=" + param + ")"; + MDC.put("param", param); } - MDC.put("url", tempUrl); } instance.set(context); return context; diff --git a/src/main/java/neatlogic/framework/logback/converter/RequestParamConverter.java b/src/main/java/neatlogic/framework/logback/converter/RequestParamConverter.java new file mode 100644 index 000000000..5cbccf88a --- /dev/null +++ b/src/main/java/neatlogic/framework/logback/converter/RequestParamConverter.java @@ -0,0 +1,36 @@ +/*Copyright (C) $today.year 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.framework.logback.converter; + +import ch.qos.logback.classic.pattern.ClassicConverter; +import ch.qos.logback.classic.spi.ILoggingEvent; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serializable; +import java.util.Map; + +public class RequestParamConverter extends ClassicConverter implements Serializable { + + @Override + public String convert(ILoggingEvent event) { + Map map = event.getMDCPropertyMap(); + String param = map.get("param"); + if (StringUtils.isNotBlank(param)) { + return param; + } + return StringUtils.EMPTY; + } +} diff --git a/src/main/java/neatlogic/module/framework/login/handler/LoginController.java b/src/main/java/neatlogic/module/framework/login/handler/LoginController.java index 66606d2d5..36f3eeb02 100644 --- a/src/main/java/neatlogic/module/framework/login/handler/LoginController.java +++ b/src/main/java/neatlogic/module/framework/login/handler/LoginController.java @@ -17,6 +17,7 @@ package neatlogic.module.framework.login.handler; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; import neatlogic.framework.asynchronization.threadlocal.RequestContext; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; @@ -98,7 +99,7 @@ public class LoginController { JSONObject jsonObj = JSON.parseObject(json); TenantContext tenantContext = TenantContext.init(); //初始化request上下文 - RequestContext.init(request, request.getRequestURI(), response).setParam(json); + RequestContext.init(request, request.getRequestURI(), response).setParam(JSON.toJSONString(jsonObj, SerializerFeature.PrettyFormat)); JSONObject resultJson = new JSONObject(); try { String userId = jsonObj.getString("userid"); diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java index 04f07b5b2..19ab5bd4a 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java @@ -96,7 +96,7 @@ public class AnonymousApiDispatcher { } InputFromContext.init(inputFrom); ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); - RequestContext.init(request, token, response).setParam(paramObj.toJSONString()); + RequestContext.init(request, token, response).setParam(JSON.toJSONString(paramObj, SerializerFeature.PrettyFormat)); ApiVo dbApiVo = apiMapper.getApiByToken(token); if (interfaceVo == null) { if (dbApiVo != null) { diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java index 2aa2f8793..d93e25d76 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java @@ -112,7 +112,10 @@ public class ApiDispatcher { inputFrom = InputFrom.UNKNOWN; } InputFromContext.init(inputFrom); - RequestContext.get().setParam(paramObj.toJSONString()); + RequestContext requestContext = RequestContext.get(); + if (requestContext != null && paramObj != null) { + requestContext.setParam(JSON.toJSONString(paramObj, SerializerFeature.PrettyFormat)); + } ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); if (paramObj == null) { paramObj = new JSONObject(); diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java index f940b3c0d..eec05d041 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java @@ -15,8 +15,10 @@ along with this program. If not, see .*/ package neatlogic.module.framework.restful.dispatch.handler; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONReader; +import com.alibaba.fastjson.serializer.SerializerFeature; import neatlogic.framework.asynchronization.threadlocal.InputFromContext; import neatlogic.framework.asynchronization.threadlocal.RequestContext; import neatlogic.framework.asynchronization.threadlocal.TenantContext; @@ -105,7 +107,7 @@ public class PublicApiDispatcher { inputFrom = InputFrom.UNKNOWN; } InputFromContext.init(inputFrom); - RequestContext.init(request, token, response).setParam(paramObj.toJSONString()); + RequestContext.init(request, token, response).setParam(JSON.toJSONString(paramObj, SerializerFeature.PrettyFormat)); //初始化时区 Cookie[] cookies = request.getCookies(); String timezone = TimeUtil.ZONE_TIME; -- Gitee From a200b39a2995d13fbbdfc29b4a5cd838a53c5886 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 10 Oct 2025 18:01:53 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=BC=82=E5=B8=B8=E6=97=B6=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1529025481113600]访问接口异常时,在打印日志时增加接口入参信息 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1529025481113600 --- .../framework/restful/dispatch/handler/ApiDispatcher.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java index d93e25d76..e314bb788 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java @@ -112,14 +112,11 @@ public class ApiDispatcher { inputFrom = InputFrom.UNKNOWN; } InputFromContext.init(inputFrom); - RequestContext requestContext = RequestContext.get(); - if (requestContext != null && paramObj != null) { - requestContext.setParam(JSON.toJSONString(paramObj, SerializerFeature.PrettyFormat)); - } ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); if (paramObj == null) { paramObj = new JSONObject(); } + RequestContext.get().setParam(JSON.toJSONString(paramObj, SerializerFeature.PrettyFormat)); ApiVo dbApiVo = apiMapper.getApiByToken(token); if (interfaceVo == null) { if (dbApiVo != null) { -- Gitee From 9e356a394f9bfaa9a0ca13b82c93422c496ebd00 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 10 Oct 2025 18:09:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=BC=82=E5=B8=B8=E6=97=B6=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1529025481113600]访问接口异常时,在打印日志时增加接口入参信息 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1529025481113600 --- .../framework/restful/dispatch/handler/ApiDispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java index e314bb788..b858c96a2 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java @@ -112,11 +112,11 @@ public class ApiDispatcher { inputFrom = InputFrom.UNKNOWN; } InputFromContext.init(inputFrom); - ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); if (paramObj == null) { paramObj = new JSONObject(); } RequestContext.get().setParam(JSON.toJSONString(paramObj, SerializerFeature.PrettyFormat)); + ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); ApiVo dbApiVo = apiMapper.getApiByToken(token); if (interfaceVo == null) { if (dbApiVo != null) { -- Gitee