refactor: 去除JMeter日志监听

This commit is contained in:
fit2-zhao 2023-09-13 09:42:28 +08:00 committed by fit2-zhao
parent 60df1ca549
commit 7f466487f8
3 changed files with 1 additions and 97 deletions

View File

@ -411,17 +411,12 @@
<appender-ref ref="runLogAppender"/>
</logger>
<!-- 自定义JMETER输出日志 -->
<appender name="JMETER_LOG" class="io.metersphere.api.jmeter.JMeterLoggerAppender"/>
<root level="INFO">
<appender-ref ref="infoAsyncAppender"/>
<appender-ref ref="console"/>
</root>
<!--将JMETER日志单独输出的包路径-->
<logger name="org.apache.jmeter" additivity="false" level="INFO">
<appender-ref ref="JMETER_LOG"/>
</logger>
<logger name="io.metersphere" additivity="false" level="${logger.level:INFO}">
<appender-ref ref="infoAsyncAppender"/>
<appender-ref ref="warnAsyncAppender"/>

View File

@ -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<ILoggingEvent> {
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);
}
}
}

View File

@ -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<String, StringBuffer> 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<K, V> extends LinkedHashMap<K, V> {
private int capacity = 3000;
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > capacity;
}
}
}