refactor: 替换服务端 console.log/error 为 winston logger
- folder-action.ts: 18处 console.log -> log.error - auth-action.ts: 4处 console.error -> log.error - dictionary-action/service.ts: 3处 -> log.error - translator-action/service.ts: 3处 -> log.error - bigmodel/translator/orchestrator.ts: console -> log.debug/info/error - bigmodel/tts.ts: console -> log.error/warn - bigmodel/dictionary/*.ts: console -> log.error/debug/info 客户端代码(browser、page.tsx)保留 console.error
This commit is contained in:
@@ -4,6 +4,9 @@ import { determineSemanticMapping } from "./stage2-semanticMapping";
|
||||
import { generateStandardForm } from "./stage3-standardForm";
|
||||
import { generateEntries } from "./stage4-entriesGeneration";
|
||||
import { LookUpError } from "@/lib/errors";
|
||||
import { createLogger } from "@/lib/logger";
|
||||
|
||||
const log = createLogger("dictionary-orchestrator");
|
||||
|
||||
export async function executeDictionaryLookup(
|
||||
text: string,
|
||||
@@ -11,35 +14,31 @@ export async function executeDictionaryLookup(
|
||||
definitionLang: string
|
||||
): Promise<ServiceOutputLookUp> {
|
||||
try {
|
||||
// ========== 阶段 1:输入分析 ==========
|
||||
console.log("[阶段1] 开始输入分析...");
|
||||
log.debug("[Stage 1] Starting input analysis");
|
||||
const analysis = await analyzeInput(text);
|
||||
|
||||
// 代码层面验证:输入是否有效
|
||||
if (!analysis.isValid) {
|
||||
console.log("[阶段1] 输入无效:", analysis.reason);
|
||||
log.debug("[Stage 1] Invalid input", { reason: analysis.reason });
|
||||
throw analysis.reason || "无效输入";
|
||||
}
|
||||
|
||||
if (analysis.isEmpty) {
|
||||
console.log("[阶段1] 输入为空");
|
||||
log.debug("[Stage 1] Empty input");
|
||||
throw "输入为空";
|
||||
}
|
||||
|
||||
console.log("[阶段1] 输入分析完成:", analysis);
|
||||
log.debug("[Stage 1] Analysis complete", { analysis });
|
||||
|
||||
// ========== 阶段 2:语义映射 ==========
|
||||
console.log("[阶段2] 开始语义映射...");
|
||||
log.debug("[Stage 2] Starting semantic mapping");
|
||||
const semanticMapping = await determineSemanticMapping(
|
||||
text,
|
||||
queryLang,
|
||||
analysis.inputLanguage || text
|
||||
);
|
||||
|
||||
console.log("[阶段2] 语义映射完成:", semanticMapping);
|
||||
log.debug("[Stage 2] Semantic mapping complete", { semanticMapping });
|
||||
|
||||
// ========== 阶段 3:生成标准形式 ==========
|
||||
console.log("[阶段3] 开始生成标准形式...");
|
||||
log.debug("[Stage 3] Generating standard form");
|
||||
|
||||
// 如果进行了语义映射,标准形式要基于映射后的结果
|
||||
// 同时传递原始输入作为语义参考
|
||||
@@ -52,16 +51,14 @@ export async function executeDictionaryLookup(
|
||||
shouldUseMapping ? text : undefined // 如果进行了映射,传递原始输入作为语义参考
|
||||
);
|
||||
|
||||
// 代码层面验证:标准形式不能为空
|
||||
if (!standardFormResult.standardForm) {
|
||||
console.error("[阶段3] 标准形式为空");
|
||||
log.error("[Stage 3] Standard form is empty");
|
||||
throw "无法生成标准形式";
|
||||
}
|
||||
|
||||
console.log("[阶段3] 标准形式生成完成:", standardFormResult);
|
||||
log.debug("[Stage 3] Standard form complete", { standardFormResult });
|
||||
|
||||
// ========== 阶段 4:生成词条 ==========
|
||||
console.log("[阶段4] 开始生成词条...");
|
||||
log.debug("[Stage 4] Generating entries");
|
||||
const entriesResult = await generateEntries(
|
||||
standardFormResult.standardForm,
|
||||
queryLang,
|
||||
@@ -71,19 +68,18 @@ export async function executeDictionaryLookup(
|
||||
: analysis.inputType
|
||||
);
|
||||
|
||||
console.log("[阶段4] 词条生成完成:", entriesResult);
|
||||
log.debug("[Stage 4] Entries complete", { entriesResult });
|
||||
|
||||
// ========== 组装最终结果 ==========
|
||||
const finalResult: ServiceOutputLookUp = {
|
||||
standardForm: standardFormResult.standardForm,
|
||||
entries: entriesResult.entries,
|
||||
};
|
||||
|
||||
console.log("[完成] 词典查询成功");
|
||||
log.info("Dictionary lookup completed successfully");
|
||||
return finalResult;
|
||||
|
||||
} catch (error) {
|
||||
console.error("[错误] 词典查询失败:", error);
|
||||
log.error("Dictionary lookup failed", { error });
|
||||
|
||||
const errorMessage = error instanceof Error ? error.message : "未知错误";
|
||||
throw new LookUpError(errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user