From 7f466487f817897295385abaa43a14dd1933f65c Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 13 Sep 2023 09:42:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=8E=BB=E9=99=A4JMeter=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src/main/resources/logback-spring.xml | 7 +-- .../api/jmeter/JMeterLoggerAppender.java | 43 ----------------- .../api/util/FixedCapacityUtils.java | 48 ------------------- 3 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java delete mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/util/FixedCapacityUtils.java diff --git a/backend/app/src/main/resources/logback-spring.xml b/backend/app/src/main/resources/logback-spring.xml index 07ab8fac2e..41d53a3f49 100644 --- a/backend/app/src/main/resources/logback-spring.xml +++ b/backend/app/src/main/resources/logback-spring.xml @@ -411,17 +411,12 @@ - - - - - - + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java b/backend/services/api-test/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java deleted file mode 100644 index 831e990105..0000000000 --- a/backend/services/api-test/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.metersphere.api.jmeter; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.classic.spi.StackTraceElementProxy; -import ch.qos.logback.core.UnsynchronizedAppenderBase; -import io.metersphere.api.util.FixedCapacityUtils; -import io.metersphere.sdk.util.DateUtils; -import io.metersphere.sdk.util.LogUtils; -import org.apache.commons.lang3.StringUtils; - -public class JMeterLoggerAppender extends UnsynchronizedAppenderBase { - private final static String THREAD_SPLIT = " "; - - @Override - public void append(ILoggingEvent event) { - try { - if (!event.getLevel().levelStr.equals(LogUtils.DEBUG) && StringUtils.isNotEmpty(event.getThreadName())) { - StringBuffer message = new StringBuffer(); - String threadName = StringUtils.substringBeforeLast(event.getThreadName(), THREAD_SPLIT); - message.append(DateUtils.getTimeStr(event.getTimeStamp())).append(StringUtils.SPACE) - .append(event.getLevel()).append(StringUtils.SPACE) - .append(event.getThreadName()).append(StringUtils.SPACE) - .append(event.getFormattedMessage()).append(StringUtils.LF); - - if (event.getThrowableProxy() != null) { - message.append(event.getThrowableProxy().getMessage()).append(StringUtils.LF); - message.append(event.getThrowableProxy().getClassName()).append(StringUtils.LF); - if (event.getThrowableProxy().getStackTraceElementProxyArray() != null) { - for (StackTraceElementProxy stackTraceElementProxy : event.getThrowableProxy().getStackTraceElementProxyArray()) { - message.append(" ").append(stackTraceElementProxy.getSTEAsString()).append(StringUtils.LF); - } - } - } - if (message != null && !message.toString().contains("java.net.UnknownHostException") - && FixedCapacityUtils.containsKey(threadName)) { - FixedCapacityUtils.get(threadName).append(message); - } - } - } catch (Exception e) { - LogUtils.error(e); - } - } -} \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/util/FixedCapacityUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/util/FixedCapacityUtils.java deleted file mode 100644 index 9d9b8c6a94..0000000000 --- a/backend/services/api-test/src/main/java/io/metersphere/api/util/FixedCapacityUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.metersphere.api.util; - -import org.apache.commons.lang3.StringUtils; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -public class FixedCapacityUtils { - private static Map fixedCapacityCache = Collections.synchronizedMap(new LRUHashMap<>()); - - public static StringBuffer get(String key) { - return fixedCapacityCache.get(key); - } - - public static boolean containsKey(String key) { - if (StringUtils.isEmpty(key)) { - return false; - } - return fixedCapacityCache.containsKey(key); - } - - public static void put(String key, StringBuffer value) { - if (!fixedCapacityCache.containsKey(key)) { - fixedCapacityCache.put(key, value); - } - } - - public static void remove(String key) { - if (fixedCapacityCache.containsKey(key)) { - fixedCapacityCache.remove(key); - } - } - - public static int size() { - return fixedCapacityCache.size(); - } - - - static class LRUHashMap extends LinkedHashMap { - private int capacity = 3000; - - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > capacity; - } - } -}