/** * Debug logging utility * Enable debug output by setting GITFOREST_DEBUG=1 environment variable */ const DEBUG = process.env.GITFOREST_DEBUG === "1" || process.env.GITFOREST_DEBUG === "true"; /** * Log a debug message (only when GITFOREST_DEBUG is enabled) */ export function debug(context: string, message: string, data?: unknown): void { if (!DEBUG) return; const timestamp = new Date().toISOString(); if (data !== undefined) { console.error(`[gitforest ${timestamp}] [${context}] ${message}`, data); } else { console.error(`[gitforest ${timestamp}] [${context}] ${message}`); } } /** * Log a debug error (only when GITFOREST_DEBUG is enabled) */ export function debugError(context: string, message: string, error: unknown): void { if (!DEBUG) return; const timestamp = new Date().toISOString(); const errorMessage = error instanceof Error ? error.message : String(error); console.error(`[gitforest ${timestamp}] [${context}] ERROR: ${message} - ${errorMessage}`); } /** * Check if debug mode is enabled */ export function isDebugEnabled(): boolean { return DEBUG; }