mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-11 07:57:28 +00:00
fix: replace printStackTrace/System.out.println with logger in JsHttpClient, PlaygroundApi, LogStatistics, CacheServiceImpl, JsPlaygroundExecutor, JsPlaygroundLogger
This commit is contained in:
@@ -534,8 +534,8 @@ public class JsHttpClient {
|
|||||||
} else {
|
} else {
|
||||||
promise.fail(result.cause());
|
promise.fail(result.cause());
|
||||||
}
|
}
|
||||||
}).onFailure(Throwable::printStackTrace);
|
}).onFailure(e -> log.error("HTTP请求失败", e));
|
||||||
|
|
||||||
// 等待响应完成(使用配置的超时时间)
|
// 等待响应完成(使用配置的超时时间)
|
||||||
HttpResponse<Buffer> response = promise.future().toCompletionStage()
|
HttpResponse<Buffer> response = promise.future().toCompletionStage()
|
||||||
.toCompletableFuture()
|
.toCompletableFuture()
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ public class JsPlaygroundExecutor {
|
|||||||
*/
|
*/
|
||||||
public List<JsPlaygroundLogger.LogEntry> getLogs() {
|
public List<JsPlaygroundLogger.LogEntry> getLogs() {
|
||||||
List<JsPlaygroundLogger.LogEntry> logs = playgroundLogger.getLogs();
|
List<JsPlaygroundLogger.LogEntry> logs = playgroundLogger.getLogs();
|
||||||
System.out.println("[JsPlaygroundExecutor] 获取日志,数量: " + logs.size());
|
log.debug("获取日志,数量: {}", logs.size());
|
||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 演练场日志收集器
|
* 演练场日志收集器
|
||||||
* 收集JavaScript执行过程中的日志信息
|
* 收集JavaScript执行过程中的日志信息
|
||||||
@@ -12,7 +15,9 @@ import java.util.List;
|
|||||||
* @author <a href="https://qaiu.top">QAIU</a>
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
*/
|
*/
|
||||||
public class JsPlaygroundLogger {
|
public class JsPlaygroundLogger {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(JsPlaygroundLogger.class);
|
||||||
|
|
||||||
// 使用线程安全的列表
|
// 使用线程安全的列表
|
||||||
private static final int MAX_LOG_SIZE = 1000;
|
private static final int MAX_LOG_SIZE = 1000;
|
||||||
private final List<LogEntry> logs = Collections.synchronizedList(new ArrayList<>());
|
private final List<LogEntry> logs = Collections.synchronizedList(new ArrayList<>());
|
||||||
@@ -81,7 +86,7 @@ public class JsPlaygroundLogger {
|
|||||||
private void log(String level, Object message, String source) {
|
private void log(String level, Object message, String source) {
|
||||||
String msg = toString(message);
|
String msg = toString(message);
|
||||||
addLog(new LogEntry(level, msg, source));
|
addLog(new LogEntry(level, msg, source));
|
||||||
System.out.println("[" + source + "PlaygroundLogger] " + level + ": " + msg);
|
log.debug("[{}PlaygroundLogger] {}: {}", source, level, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,7 +130,7 @@ public class JsPlaygroundLogger {
|
|||||||
msg = msg + ": " + throwable.getMessage();
|
msg = msg + ": " + throwable.getMessage();
|
||||||
}
|
}
|
||||||
addLog(new LogEntry("ERROR", msg, "JS"));
|
addLog(new LogEntry("ERROR", msg, "JS"));
|
||||||
System.out.println("[JSPlaygroundLogger] ERROR: " + msg);
|
log.debug("[JSPlaygroundLogger] ERROR: {}", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 以下是供Java层调用的内部方法 =====
|
// ===== 以下是供Java层调用的内部方法 =====
|
||||||
@@ -167,7 +172,7 @@ public class JsPlaygroundLogger {
|
|||||||
msg = msg + ": " + throwable.getMessage();
|
msg = msg + ": " + throwable.getMessage();
|
||||||
}
|
}
|
||||||
addLog(new LogEntry("ERROR", msg, "JAVA"));
|
addLog(new LogEntry("ERROR", msg, "JAVA"));
|
||||||
System.out.println("[JAVAPlaygroundLogger] ERROR: " + msg);
|
log.debug("[JAVAPlaygroundLogger] ERROR: {}", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ public class LogStatistics implements AfterInterceptor {
|
|||||||
.execute(info)
|
.execute(info)
|
||||||
.onSuccess(res -> {
|
.onSuccess(res -> {
|
||||||
log.info("inserted log: id={}, path={}, code={}", info.getId(), info.getPath(), info.getCode());
|
log.info("inserted log: id={}, path={}, code={}", info.getId(), info.getPath(), info.getCode());
|
||||||
}).onFailure(Throwable::printStackTrace);
|
}).onFailure(e -> log.error("插入解析日志失败: id={}", info.getId(), e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -704,6 +704,7 @@ public class PlaygroundApi {
|
|||||||
if (throwable == null) {
|
if (throwable == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
log.error("获取异常堆栈信息", throwable);
|
||||||
java.io.StringWriter sw = new java.io.StringWriter();
|
java.io.StringWriter sw = new java.io.StringWriter();
|
||||||
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
|
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
|
||||||
throwable.printStackTrace(pw);
|
throwable.printStackTrace(pw);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class CacheServiceImpl implements CacheService {
|
|||||||
promise.complete(result);
|
promise.complete(result);
|
||||||
// 更新缓存
|
// 更新缓存
|
||||||
cacheManager.cacheShareLink(cacheLinkInfo);
|
cacheManager.cacheShareLink(cacheLinkInfo);
|
||||||
cacheManager.updateTotalByField(cacheKey, CacheTotalField.API_PARSER_TOTAL).onFailure(Throwable::printStackTrace);
|
cacheManager.updateTotalByField(cacheKey, CacheTotalField.API_PARSER_TOTAL).onFailure(e -> log.error("更新API解析计数失败: cacheKey={}", cacheKey, e));
|
||||||
}).onFailure(promise::fail);
|
}).onFailure(promise::fail);
|
||||||
} else {
|
} else {
|
||||||
// 缓存命中,生成过期时间并生成下载命令
|
// 缓存命中,生成过期时间并生成下载命令
|
||||||
@@ -120,7 +120,7 @@ public class CacheServiceImpl implements CacheService {
|
|||||||
|
|
||||||
promise.complete(result);
|
promise.complete(result);
|
||||||
cacheManager.updateTotalByField(cacheKey, CacheTotalField.CACHE_HIT_TOTAL)
|
cacheManager.updateTotalByField(cacheKey, CacheTotalField.CACHE_HIT_TOTAL)
|
||||||
.onFailure(Throwable::printStackTrace);
|
.onFailure(e -> log.error("更新缓存命中计数失败: cacheKey={}", cacheKey, e));
|
||||||
}
|
}
|
||||||
}).onFailure(t -> promise.fail(t.fillInStackTrace()));
|
}).onFailure(t -> promise.fail(t.fillInStackTrace()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user