From 5fce7ee1c246dfc8326fad27f3c63e6b45a2a05f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 24 May 2023 15:54:36 +0800 Subject: [PATCH] build: logs refactor --- .../plugin/api/dto/TestElementDTO.java | 4 +-- .../io/metersphere/sdk/util/LogUtils.java | 29 ++++--------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/backend/framework/plugin/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java b/backend/framework/plugin/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java index c522be7bb0..1f67b3ea66 100644 --- a/backend/framework/plugin/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java +++ b/backend/framework/plugin/src/main/java/io/metersphere/plugin/api/dto/TestElementDTO.java @@ -24,7 +24,7 @@ public abstract class TestElementDTO { private String clazzName = TestElementDTO.class.getCanonicalName(); // 当前组件唯一标示 - private String resourceId; + private String uuid; // 组件标签名称 private String name; @@ -36,7 +36,7 @@ public abstract class TestElementDTO { private String index; // 是否禁用/启用标示 - private boolean enable = true; + private boolean enable; // 子组件 private LinkedList hashTree; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/LogUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/LogUtils.java index 6b4652bb30..482a99bc9f 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/LogUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/LogUtils.java @@ -1,5 +1,6 @@ package io.metersphere.sdk.util; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -200,15 +201,12 @@ public class LogUtils { * @return */ private static String getLogClass() { - String str = ""; - StackTraceElement[] stack = (new Throwable()).getStackTrace(); if (stack.length > 3) { StackTraceElement ste = stack[3]; - str = ste.getClassName();// 类名称 + return ste.getClassName(); } - - return str; + return StringUtils.EMPTY; } /** @@ -217,19 +215,15 @@ public class LogUtils { * @return */ private static String getLogMethod() { - String str = ""; - StackTraceElement[] stack = (new Throwable()).getStackTrace(); - if (stack.length > 4) { + if (ArrayUtils.isNotEmpty(stack) && stack.length > 4) { StackTraceElement ste = stack[4]; - str = "Method[" + ste.getMethodName() + "]";// 方法名称 + return "Method[" + ste.getMethodName() + "]"; } - - return str; + return StringUtils.EMPTY; } public static String toString(Throwable e) { - try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw);) { //将出错的栈信息输出到printWriter中 @@ -241,15 +235,4 @@ public class LogUtils { return ex.getMessage(); } } - - public static String getExceptionDetailsToStr(Exception e) { - StringBuilder sb = new StringBuilder(e.toString()); - StackTraceElement[] stackElements = e.getStackTrace(); - for (StackTraceElement stackTraceElement : stackElements) { - sb.append(stackTraceElement.toString()); - sb.append(StringUtils.LF); - } - sb.append(StringUtils.LF); - return sb.toString(); - } }