{"version":3,"sources":["../../../src/server/node-environment-extensions/console-file.tsx"],"sourcesContent":["import { consoleAsyncStorage } from '../app-render/console-async-storage.external'\nimport { getFileLogger } from '../dev/browser-logs/file-logger'\nimport { formatConsoleArgs } from '../../client/lib/console'\n\ntype InterceptableConsoleMethod =\n | 'error'\n | 'assert'\n | 'debug'\n | 'dir'\n | 'dirxml'\n | 'group'\n | 'groupCollapsed'\n | 'groupEnd'\n | 'info'\n | 'log'\n | 'table'\n | 'trace'\n | 'warn'\n\n// Based on https://github.com/facebook/react/blob/28dc0776be2e1370fe217549d32aee2519f0cf05/packages/react-server/src/ReactFlightServer.js#L248\nfunction patchConsoleMethodDEV(methodName: InterceptableConsoleMethod): void {\n const descriptor = Object.getOwnPropertyDescriptor(console, methodName)\n if (\n descriptor &&\n (descriptor.configurable || descriptor.writable) &&\n typeof descriptor.value === 'function'\n ) {\n const originalMethod = descriptor.value\n const originalName = Object.getOwnPropertyDescriptor(originalMethod, 'name')\n const wrapperMethod = function (this: typeof console, ...args: any[]) {\n const consoleStore = consoleAsyncStorage.getStore()\n\n if (consoleStore?.dim === true) {\n // In this context the log args are already dimmed. We use the console store\n // to decide if this log is ignorable for reporting in our file logger.\n return originalMethod.apply(this, args)\n } else {\n const ret = originalMethod.apply(this, args)\n\n const fileLogger = getFileLogger()\n const message = formatConsoleArgs(args)\n // Strip ANSI escape codes for file logging\n // eslint-disable-next-line no-control-regex\n const ansiEscapeRegex = new RegExp('\\u001b\\\\[[0-9;]*m', 'g')\n const cleanMessage = message.replace(ansiEscapeRegex, '')\n fileLogger.logServer(methodName.toUpperCase(), cleanMessage)\n return ret\n }\n }\n if (originalName) {\n Object.defineProperty(wrapperMethod, 'name', originalName)\n }\n Object.defineProperty(console, methodName, {\n value: wrapperMethod,\n })\n }\n}\n\nif (process.env.NODE_ENV === 'development') {\n patchConsoleMethodDEV('error')\n patchConsoleMethodDEV('assert')\n patchConsoleMethodDEV('debug')\n patchConsoleMethodDEV('dir')\n patchConsoleMethodDEV('dirxml')\n patchConsoleMethodDEV('group')\n patchConsoleMethodDEV('groupCollapsed')\n patchConsoleMethodDEV('groupEnd')\n patchConsoleMethodDEV('info')\n patchConsoleMethodDEV('log')\n patchConsoleMethodDEV('table')\n patchConsoleMethodDEV('trace')\n patchConsoleMethodDEV('warn')\n}\n"],"names":["patchConsoleMethodDEV","methodName","descriptor","Object","getOwnPropertyDescriptor","console","configurable","writable","value","originalMethod","originalName","wrapperMethod","args","consoleStore","consoleAsyncStorage","getStore","dim","apply","ret","fileLogger","getFileLogger","message","formatConsoleArgs","ansiEscapeRegex","RegExp","cleanMessage","replace","logServer","toUpperCase","defineProperty","process","env","NODE_ENV"],"mappings":";;;;6CAAoC;4BACN;yBACI;AAiBlC,+IAA+I;AAC/I,SAASA,sBAAsBC,UAAsC;IACnE,MAAMC,aAAaC,OAAOC,wBAAwB,CAACC,SAASJ;IAC5D,IACEC,cACCA,CAAAA,WAAWI,YAAY,IAAIJ,WAAWK,QAAQ,AAAD,KAC9C,OAAOL,WAAWM,KAAK,KAAK,YAC5B;QACA,MAAMC,iBAAiBP,WAAWM,KAAK;QACvC,MAAME,eAAeP,OAAOC,wBAAwB,CAACK,gBAAgB;QACrE,MAAME,gBAAgB,SAAgC,GAAGC,IAAW;YAClE,MAAMC,eAAeC,gDAAmB,CAACC,QAAQ;YAEjD,IAAIF,CAAAA,gCAAAA,aAAcG,GAAG,MAAK,MAAM;gBAC9B,4EAA4E;gBAC5E,uEAAuE;gBACvE,OAAOP,eAAeQ,KAAK,CAAC,IAAI,EAAEL;YACpC,OAAO;gBACL,MAAMM,MAAMT,eAAeQ,KAAK,CAAC,IAAI,EAAEL;gBAEvC,MAAMO,aAAaC,IAAAA,yBAAa;gBAChC,MAAMC,UAAUC,IAAAA,0BAAiB,EAACV;gBAClC,2CAA2C;gBAC3C,4CAA4C;gBAC5C,MAAMW,kBAAkB,IAAIC,OAAO,qBAAqB;gBACxD,MAAMC,eAAeJ,QAAQK,OAAO,CAACH,iB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