export type LogLevel = "INF" | "WRN" | "ERR" | "TRC" | "DBG"; const TAIPEI_FORMATTER = new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Taipei", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false, }); export function formatTaipeiTimestamp(date: Date = new Date()): string { const parts = TAIPEI_FORMATTER.formatToParts(date); const get = (type: string) => parts.find((p) => p.type === type)?.value ?? "00"; return `${get("year")}/${get("month")}/${get("day")} ${get("hour")}:${get("minute")}:${get("second")}`; } export function log(stage: string, level: LogLevel, message: string): void { const line = `[${formatTaipeiTimestamp()}][${stage}][${level}]: ${message}`; if (level === "ERR") { console.error(line); } else if (level === "WRN") { console.warn(line); } else { console.log(line); } }