{"version":3,"file":"log-console-capture.cjs","names":["getGlobalConsole"],"sources":["../../../src/common/log/log-console-capture.ts"],"sourcesContent":["import type { LoggerInterface } from './log-base'\nimport { getGlobalConsole } from './log-console-original'\n\nlet onlyOnce: boolean | undefined\n\n/**\n * Overrides the global console methods to capture log messages and forward them to the provided logger.\n * Also captures window errors and unhandled rejections and logs them using the provided logger.\n *\n * @param log - The logger to which the captured log messages will be forwarded.\n */\nexport function logCaptureConsole(log: LoggerInterface) {\n  if (onlyOnce) {\n    log.error('use logCaptureConsole only once!')\n    return\n  }\n\n  onlyOnce = true\n\n  // Save the original console methods\n  const originalConsole = getGlobalConsole()\n\n  if (!originalConsole) {\n    globalThis.console = {} as any\n  }\n\n  globalThis.console.log = (...args: any[]) => log.debug(...args)\n  globalThis.console.debug = (...args: any[]) => log.debug(...args)\n  globalThis.console.warn = (...args: any[]) => log.warn(...args)\n  globalThis.console.error = (...args: any[]) => log.error(...args)\n  globalThis.console.info = (...args: any[]) => log.info(...args)\n\n  globalThis.addEventListener?.('unhandledrejection', (event: any) => {\n    log.error('onUnhandledrejection', event)\n  })\n\n  globalThis.addEventListener?.('error', (event: any) => {\n    log.error('onError', event)\n  })\n}\n"],"mappings":";;;;AAGA,IAAI;;;;;;;AAQJ,SAAgB,kBAAkB,KAAsB;AACtD,KAAI,UAAU;AACZ,MAAI,MAAM,mCAAmC;AAC7C;;AAGF,YAAW;AAKX,KAAI,CAFoBA,0DAAkB,CAGxC,YAAW,UAAU,EAAE;AAGzB,YAAW,QAAQ,OAAO,GAAG,SAAgB,IAAI,MAAM,GAAG,KAAK;AAC/D,YAAW,QAAQ,SAAS,GAAG,SAAgB,IAAI,MAAM,GAAG,KAAK;AACjE,YAAW,QAAQ,QAAQ,GAAG,SAAgB,IAAI,KAAK,GAAG,KAAK;AAC/D,YAAW,QAAQ,SAAS,GAAG,SAAgB,IAAI,MAAM,GAAG,KAAK;AACjE,YAAW,QAAQ,QAAQ,GAAG,SAAgB,IAAI,KAAK,GAAG,KAAK;AAE/D,YAAW,mBAAmB,uBAAuB,UAAe;AAClE,MAAI,MAAM,wBAAwB,MAAM;GACxC;AAEF,YAAW,mBAAmB,UAAU,UAAe;AACrD,MAAI,MAAM,WAAW,MAAM;GAC3B"}