@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 28 lines 839 Bytes
Raw
1 export interface DebugLogger {
2 readonly isEnabled: () => boolean;
3 readonly log: (event: string, data?: Record<string, unknown>) => void;
4 }
5
6 function globalValue(name: string): unknown {
7 return typeof globalThis === "undefined"
8 ? undefined
9 : (globalThis as Record<string, unknown>)[name];
10 }
11
12 export function createDebugLogger(namespace: string): DebugLogger {
13 const isEnabled = () => {
14 const filter = globalValue("__T3_DEBUG__");
15 return filter === true || (Array.isArray(filter) && filter.includes(namespace));
16 };
17 const log = (event: string, data?: Record<string, unknown>) => {
18 if (!isEnabled()) {
19 return;
20 }
21 if (data === undefined) {
22 console.log(`[t3-${namespace}] ${event}`);
23 } else {
24 console.log(`[t3-${namespace}] ${event}`, data);
25 }
26 };
27 return { isEnabled, log };
28 }