|
@@ -44,6 +44,22 @@ public class RequestLogAspect {
|
|
|
private SerializeConfig serializeConfig;
|
|
|
private SerializerWrapper serializerWrapper;
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取完整的请求路径, 包含 queryString
|
|
|
+ *
|
|
|
+ * @param request 当前请求
|
|
|
+ * @return 完整的请求路径
|
|
|
+ */
|
|
|
+ public static String getFullRequestUrl(HttpServletRequest request) {
|
|
|
+ if (request == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(request.getQueryString())) {
|
|
|
+ return request.getRequestURL().toString();
|
|
|
+ }
|
|
|
+ return request.getRequestURL().append('?').append(request.getQueryString()).toString();
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
public void setSerialize(SerializeConfig serialize) {
|
|
|
this.serializeConfig = serialize;
|
|
@@ -78,8 +94,8 @@ public class RequestLogAspect {
|
|
|
Object result = null;
|
|
|
try {
|
|
|
result = proceedingJoinPoint.proceed();
|
|
|
- } catch (Throwable th) {
|
|
|
- log.warn("Request warn : {}", JSON.toJSONString(requestInfo),th);
|
|
|
+ } catch (Throwable th) {
|
|
|
+ log.warn("Request warn : {}", JSON.toJSONString(requestInfo), th);
|
|
|
throw th;
|
|
|
}
|
|
|
// 配置明确指定为 true,才使用全返回值
|
|
@@ -149,6 +165,23 @@ public class RequestLogAspect {
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
+ @Component
|
|
|
+ @AllArgsConstructor
|
|
|
+ @NoArgsConstructor
|
|
|
+ public static class SerializeConfig {
|
|
|
+ @Value("${api.access.log.serialize.result-full:false}")
|
|
|
+ protected volatile Boolean resultFull;
|
|
|
+ @Value("${api.access.log.aop.enable:true}")
|
|
|
+ private volatile Boolean aopLog;
|
|
|
+ @Value("${api.access.log.serialize.args-full:true}")
|
|
|
+ private volatile Boolean argsFull;
|
|
|
+ @Value("${api.access.log.serialize.args-max-length:2048}")
|
|
|
+ private volatile Integer argsMaxLength;
|
|
|
+ @Value("${api.access.log.serialize.result-max-length:2048}")
|
|
|
+ private volatile Integer resultMaxLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
public class RequestInfo {
|
|
|
private String ip;
|
|
|
private String url;
|
|
@@ -169,38 +202,4 @@ public class RequestLogAspect {
|
|
|
private transient Exception exception;
|
|
|
private String[] stacktrace;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- @Data
|
|
|
- @Component
|
|
|
- @AllArgsConstructor
|
|
|
- @NoArgsConstructor
|
|
|
- public static class SerializeConfig {
|
|
|
- @Value("${api.access.log.aop.enable:true}")
|
|
|
- private volatile Boolean aopLog;
|
|
|
- @Value("${api.access.log.serialize.args-full:true}")
|
|
|
- private volatile Boolean argsFull;
|
|
|
- @Value("${api.access.log.serialize.args-max-length:2048}")
|
|
|
- private volatile Integer argsMaxLength;
|
|
|
- @Value("${api.access.log.serialize.result-full:false}")
|
|
|
- protected volatile Boolean resultFull;
|
|
|
- @Value("${api.access.log.serialize.result-max-length:2048}")
|
|
|
- private volatile Integer resultMaxLength;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取完整的请求路径, 包含 queryString
|
|
|
- *
|
|
|
- * @param request 当前请求
|
|
|
- * @return 完整的请求路径
|
|
|
- */
|
|
|
- public static String getFullRequestUrl(HttpServletRequest request) {
|
|
|
- if (request == null) {
|
|
|
- return "";
|
|
|
- }
|
|
|
- if (StrUtil.isBlank(request.getQueryString())) {
|
|
|
- return request.getRequestURL().toString();
|
|
|
- }
|
|
|
- return request.getRequestURL().append('?').append(request.getQueryString()).toString();
|
|
|
- }
|
|
|
}
|