日志控制
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ChatAIService } from '../core/ChatAIService';
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
/**
|
||||
* ChatAI 批量测试运行器 - 纯脚本版本
|
||||
@@ -14,7 +15,7 @@ export class ChatAIBatchTestRunner {
|
||||
private isRunning: boolean = false;
|
||||
|
||||
constructor() {
|
||||
console.log("[ChatAIBatchTestRunner] 测试运行器已初始化");
|
||||
logger.log("[ChatAIBatchTestRunner] 测试运行器已初始化");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,13 +33,13 @@ export class ChatAIBatchTestRunner {
|
||||
*/
|
||||
public async runBatchTest(): Promise<void> {
|
||||
if (this.isRunning) {
|
||||
console.log("[ChatAIBatchTestRunner] 测试已在运行中,请等待完成...");
|
||||
logger.log("[ChatAIBatchTestRunner] 测试已在运行中,请等待完成...");
|
||||
return;
|
||||
}
|
||||
|
||||
this.isRunning = true;
|
||||
console.log("[ChatAIBatchTestRunner] 开始批量测试角色ID 10001-10030");
|
||||
console.log("[ChatAIBatchTestRunner] 每次测试间隔10秒");
|
||||
logger.log("[ChatAIBatchTestRunner] 开始批量测试角色ID 10001-10030");
|
||||
logger.log("[ChatAIBatchTestRunner] 每次测试间隔10秒");
|
||||
|
||||
const startTime = Date.now();
|
||||
const successIds: number[] = [];
|
||||
@@ -47,7 +48,7 @@ export class ChatAIBatchTestRunner {
|
||||
|
||||
// 测试角色ID 10001-10030
|
||||
for (let roleId = 10001; roleId <= 10030; roleId++) {
|
||||
console.log(`[ChatAIBatchTestRunner] 正在测试角色ID: ${roleId}`);
|
||||
logger.log(`[ChatAIBatchTestRunner] 正在测试角色ID: ${roleId}`);
|
||||
|
||||
const testStartTime = Date.now();
|
||||
|
||||
@@ -57,12 +58,12 @@ export class ChatAIBatchTestRunner {
|
||||
|
||||
if (response && response.trim() !== "") {
|
||||
successIds.push(roleId);
|
||||
console.log(`[ChatAIBatchTestRunner] ✅ 角色 ${roleId} 测试成功 (${testDuration}ms)`);
|
||||
console.log(`[ChatAIBatchTestRunner] 响应预览: ${response.substring(0, 50)}...`);
|
||||
logger.log(`[ChatAIBatchTestRunner] ✅ 角色 ${roleId} 测试成功 (${testDuration}ms)`);
|
||||
logger.log(`[ChatAIBatchTestRunner] 响应预览: ${response.substring(0, 50)}...`);
|
||||
} else {
|
||||
failureIds.push(roleId);
|
||||
errorDetails[roleId] = "返回空响应";
|
||||
console.log(`[ChatAIBatchTestRunner] ❌ 角色 ${roleId} 返回空响应 (${testDuration}ms)`);
|
||||
logger.log(`[ChatAIBatchTestRunner] ❌ 角色 ${roleId} 返回空响应 (${testDuration}ms)`);
|
||||
}
|
||||
} catch (error) {
|
||||
const testDuration = Date.now() - testStartTime;
|
||||
@@ -70,12 +71,12 @@ export class ChatAIBatchTestRunner {
|
||||
|
||||
failureIds.push(roleId);
|
||||
errorDetails[roleId] = errorMessage;
|
||||
console.log(`[ChatAIBatchTestRunner] ❌ 角色 ${roleId} 测试失败 (${testDuration}ms): ${errorMessage}`);
|
||||
logger.log(`[ChatAIBatchTestRunner] ❌ 角色 ${roleId} 测试失败 (${testDuration}ms): ${errorMessage}`);
|
||||
}
|
||||
|
||||
// 等待10秒(最后一个不需要等待)
|
||||
if (roleId < 10030) {
|
||||
console.log(`[ChatAIBatchTestRunner] 等待10秒后继续下一个测试...`);
|
||||
logger.log(`[ChatAIBatchTestRunner] 等待10秒后继续下一个测试...`);
|
||||
await this.delay(10);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ export class ChatAIBatchTestRunner {
|
||||
this.printFinalReport(successIds, failureIds, errorDetails, totalDuration);
|
||||
|
||||
this.isRunning = false;
|
||||
console.log("[ChatAIBatchTestRunner] 批量测试完成!");
|
||||
logger.log("[ChatAIBatchTestRunner] 批量测试完成!");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,44 +104,44 @@ export class ChatAIBatchTestRunner {
|
||||
const failureCount = failureIds.length;
|
||||
const successRate = ((successCount / totalTests) * 100).toFixed(2);
|
||||
|
||||
console.log("\n" + "=".repeat(60));
|
||||
console.log(" ChatAI 批量测试报告");
|
||||
console.log("=".repeat(60));
|
||||
console.log(`测试时间: ${new Date().toLocaleString()}`);
|
||||
console.log(`总测试数: ${totalTests}`);
|
||||
console.log(`成功数量: ${successCount}`);
|
||||
console.log(`失败数量: ${failureCount}`);
|
||||
console.log(`成功率: ${successRate}%`);
|
||||
console.log(`总耗时: ${(totalDuration / 1000).toFixed(2)}秒`);
|
||||
console.log(`平均耗时: ${(totalDuration / totalTests / 1000).toFixed(2)}秒/测试`);
|
||||
logger.log("\n" + "=".repeat(60));
|
||||
logger.log(" ChatAI 批量测试报告");
|
||||
logger.log("=".repeat(60));
|
||||
logger.log(`测试时间: ${new Date().toLocaleString()}`);
|
||||
logger.log(`总测试数: ${totalTests}`);
|
||||
logger.log(`成功数量: ${successCount}`);
|
||||
logger.log(`失败数量: ${failureCount}`);
|
||||
logger.log(`成功率: ${successRate}%`);
|
||||
logger.log(`总耗时: ${(totalDuration / 1000).toFixed(2)}秒`);
|
||||
logger.log(`平均耗时: ${(totalDuration / totalTests / 1000).toFixed(2)}秒/测试`);
|
||||
|
||||
console.log("\n" + "-".repeat(30) + " 成功的角色ID " + "-".repeat(30));
|
||||
logger.log("\n" + "-".repeat(30) + " 成功的角色ID " + "-".repeat(30));
|
||||
if (successIds.length > 0) {
|
||||
const successList = this.formatIdList(successIds);
|
||||
console.log(successList);
|
||||
logger.log(successList);
|
||||
} else {
|
||||
console.log("无成功案例");
|
||||
logger.log("无成功案例");
|
||||
}
|
||||
|
||||
console.log("\n" + "-".repeat(30) + " 失败的角色ID " + "-".repeat(30));
|
||||
logger.log("\n" + "-".repeat(30) + " 失败的角色ID " + "-".repeat(30));
|
||||
if (failureIds.length > 0) {
|
||||
const failureList = this.formatIdList(failureIds);
|
||||
console.log(failureList);
|
||||
logger.log(failureList);
|
||||
|
||||
console.log("\n" + "-".repeat(25) + " 失败详情 " + "-".repeat(25));
|
||||
logger.log("\n" + "-".repeat(25) + " 失败详情 " + "-".repeat(25));
|
||||
failureIds.forEach(roleId => {
|
||||
console.log(`角色 ${roleId}: ${errorDetails[roleId]}`);
|
||||
logger.log(`角色 ${roleId}: ${errorDetails[roleId]}`);
|
||||
});
|
||||
} else {
|
||||
console.log("无失败案例");
|
||||
logger.log("无失败案例");
|
||||
}
|
||||
|
||||
console.log("\n" + "=".repeat(60));
|
||||
logger.log("\n" + "=".repeat(60));
|
||||
|
||||
// 输出简洁版结果供复制使用
|
||||
console.log("\n简洁结果:");
|
||||
console.log(`成功(${successCount}): ${successIds.join(',')}`);
|
||||
console.log(`失败(${failureCount}): ${failureIds.join(',')}`);
|
||||
logger.log("\n简洁结果:");
|
||||
logger.log(`成功(${successCount}): ${successIds.join(',')}`);
|
||||
logger.log(`失败(${failureCount}): ${failureIds.join(',')}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user