Files
multica/packages/core/logger.ts
Naiyuan Qing e1e7f68330 feat: extract packages/core — Turborepo infrastructure + headless business logic
Phase 1: Monorepo infrastructure
- Add Turborepo with turbo.json pipeline (build, dev, typecheck, test)
- Update pnpm-workspace.yaml to include packages/*
- Create shared TypeScript config (packages/tsconfig)

Phase 2: Extract packages/core (zero react-dom, all-platform reuse)
- Move domain types, API client, logger, utils → packages/core/
- Move TanStack Query modules (issues, inbox, workspace, runtimes)
- Move Zustand stores (auth, workspace, issues, navigation, modals)
- Move realtime sync (WSProvider, hooks, ws-updaters)
- Refactor auth/workspace stores to factory pattern for DI
- Refactor ApiClient with onUnauthorized callback
- Refactor useWorkspaceId to React Context (WorkspaceIdProvider)
- Refactor WSProvider to accept wsUrl + store props
- Create apps/web/platform/ bridge layer (api singleton, store instances)
- Update 91 import paths across apps/web/
- Fix 3 test files for new import paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 10:20:00 +08:00

52 lines
1.3 KiB
TypeScript

type LogLevel = "debug" | "info" | "warn" | "error";
const COLORS: Record<LogLevel, string> = {
debug: "color:#888",
info: "color:#2196F3",
warn: "color:#FF9800",
error: "color:#F44336;font-weight:bold",
};
const CONSOLE_METHOD: Record<LogLevel, "log" | "info" | "warn" | "error"> = {
debug: "log",
info: "info",
warn: "warn",
error: "error",
};
export interface Logger {
debug(msg: string, ...data: unknown[]): void;
info(msg: string, ...data: unknown[]): void;
warn(msg: string, ...data: unknown[]): void;
error(msg: string, ...data: unknown[]): void;
}
export function createLogger(namespace: string): Logger {
const make =
(level: LogLevel) =>
(msg: string, ...data: unknown[]) => {
const ts = new Date().toISOString().slice(11, 23);
const prefix = `%c${ts} [${namespace}]`;
if (data.length > 0) {
console[CONSOLE_METHOD[level]](prefix, COLORS[level], msg, ...data);
} else {
console[CONSOLE_METHOD[level]](prefix, COLORS[level], msg);
}
};
return {
debug: make("debug"),
info: make("info"),
warn: make("warn"),
error: make("error"),
};
}
/** No-op logger for when logging is not needed. */
export const noopLogger: Logger = {
debug() {},
info() {},
warn() {},
error() {},
};