mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +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 {
|
||||
promise.fail(result.cause());
|
||||
}
|
||||
}).onFailure(Throwable::printStackTrace);
|
||||
|
||||
}).onFailure(e -> log.error("HTTP请求失败", e));
|
||||
|
||||
// 等待响应完成(使用配置的超时时间)
|
||||
HttpResponse<Buffer> response = promise.future().toCompletionStage()
|
||||
.toCompletableFuture()
|
||||
|
||||
@@ -355,7 +355,7 @@ public class JsPlaygroundExecutor {
|
||||
*/
|
||||
public List<JsPlaygroundLogger.LogEntry> getLogs() {
|
||||
List<JsPlaygroundLogger.LogEntry> logs = playgroundLogger.getLogs();
|
||||
System.out.println("[JsPlaygroundExecutor] 获取日志,数量: " + logs.size());
|
||||
log.debug("获取日志,数量: {}", logs.size());
|
||||
return logs;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 演练场日志收集器
|
||||
* 收集JavaScript执行过程中的日志信息
|
||||
@@ -12,7 +15,9 @@ import java.util.List;
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class JsPlaygroundLogger {
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JsPlaygroundLogger.class);
|
||||
|
||||
// 使用线程安全的列表
|
||||
private static final int MAX_LOG_SIZE = 1000;
|
||||
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) {
|
||||
String msg = toString(message);
|
||||
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();
|
||||
}
|
||||
addLog(new LogEntry("ERROR", msg, "JS"));
|
||||
System.out.println("[JSPlaygroundLogger] ERROR: " + msg);
|
||||
log.debug("[JSPlaygroundLogger] ERROR: {}", msg);
|
||||
}
|
||||
|
||||
// ===== 以下是供Java层调用的内部方法 =====
|
||||
@@ -167,7 +172,7 @@ public class JsPlaygroundLogger {
|
||||
msg = msg + ": " + throwable.getMessage();
|
||||
}
|
||||
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)
|
||||
.onSuccess(res -> {
|
||||
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) {
|
||||
return "";
|
||||
}
|
||||
log.error("获取异常堆栈信息", throwable);
|
||||
java.io.StringWriter sw = new java.io.StringWriter();
|
||||
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
|
||||
throwable.printStackTrace(pw);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class CacheServiceImpl implements CacheService {
|
||||
promise.complete(result);
|
||||
// 更新缓存
|
||||
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);
|
||||
} else {
|
||||
// 缓存命中,生成过期时间并生成下载命令
|
||||
@@ -120,7 +120,7 @@ public class CacheServiceImpl implements CacheService {
|
||||
|
||||
promise.complete(result);
|
||||
cacheManager.updateTotalByField(cacheKey, CacheTotalField.CACHE_HIT_TOTAL)
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
.onFailure(e -> log.error("更新缓存命中计数失败: cacheKey={}", cacheKey, e));
|
||||
}
|
||||
}).onFailure(t -> promise.fail(t.fillInStackTrace()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user