refactor(logging): centralize console output
This commit is contained in:
@@ -25,7 +25,9 @@ import { chatRepository } from "@/data/repositories/chat_repository";
|
||||
import type { IChatRepository } from "@/data/repositories/interfaces";
|
||||
import { ChatStorage } from "@/data/storage/chat/chat_storage";
|
||||
import { ChatSendResponse } from "@/data/dto/chat/chat_send_response";
|
||||
import { formatDate, Result } from "@/utils";
|
||||
import { formatDate, Result, Logger } from "@/utils";
|
||||
|
||||
const log = new Logger("StoresChatChatMachineHelpers");
|
||||
|
||||
// ============================================================
|
||||
// Constants
|
||||
@@ -161,7 +163,7 @@ export async function readAndSyncHistory(): Promise<{
|
||||
Result.isOk(localResult) && localResult.data
|
||||
? localMessagesToUi(localResult.data)
|
||||
: [];
|
||||
console.log("[chat-machine] loadHistory LOCAL DONE", {
|
||||
log.debug("[chat-machine] loadHistory LOCAL DONE", {
|
||||
count: localMessages.length,
|
||||
});
|
||||
|
||||
@@ -169,7 +171,7 @@ export async function readAndSyncHistory(): Promise<{
|
||||
const networkResult = await chatRepo.getHistory(PAGE_SIZE, 0);
|
||||
if (!Result.isOk(networkResult)) {
|
||||
// network 失败 —— 返空 messages(不让 UI 卡住)
|
||||
console.error(
|
||||
log.error(
|
||||
"[chat-machine] loadHistory NETWORK FAILED",
|
||||
networkResult.success ? null : (networkResult as { error: unknown }).error,
|
||||
);
|
||||
@@ -178,7 +180,7 @@ export async function readAndSyncHistory(): Promise<{
|
||||
const fallbackMessages =
|
||||
localMessages.length === 0 ? [greetingMessage] : localMessages;
|
||||
if (fallbackMessages[0] === greetingMessage) {
|
||||
console.log(
|
||||
log.debug(
|
||||
"[chat-machine] loadHistory EMPTY → prepend greeting (network-failed path)",
|
||||
);
|
||||
}
|
||||
@@ -192,14 +194,14 @@ export async function readAndSyncHistory(): Promise<{
|
||||
};
|
||||
}
|
||||
const networkUi = localMessagesToUi(networkResult.data.messages);
|
||||
console.log("[chat-machine] loadHistory NETWORK DONE", {
|
||||
log.debug("[chat-machine] loadHistory NETWORK DONE", {
|
||||
count: networkUi.length,
|
||||
});
|
||||
|
||||
// 3. 用 network 覆盖 local
|
||||
const saveResult = await chatRepo.saveMessagesToLocal(networkResult.data.messages);
|
||||
const localOverwritten = Result.isOk(saveResult);
|
||||
console.log("[chat-machine] loadHistory SAVE TO LOCAL DONE", {
|
||||
log.debug("[chat-machine] loadHistory SAVE TO LOCAL DONE", {
|
||||
localOverwritten,
|
||||
});
|
||||
|
||||
@@ -207,7 +209,7 @@ export async function readAndSyncHistory(): Promise<{
|
||||
const finalMessages =
|
||||
networkUi.length === 0 ? [greetingMessage] : networkUi;
|
||||
if (finalMessages[0] === greetingMessage) {
|
||||
console.log("[chat-machine] loadHistory EMPTY → prepend greeting");
|
||||
log.debug("[chat-machine] loadHistory EMPTY → prepend greeting");
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user