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C;YAC7C,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE;gBACxC,cAAc,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;aAC7C;YAED,iBAAiB,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QACrC,CAAC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,SAAS,iBAAiB,CACxB,KAAe,EACf,gBAAgC,EAChC,IAAe;QAEf,aAAa,CAAC,qBAAqB,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAAC,KAAK,CACzF,KAAK,CAAC,EAAE;YACN,eAAe,CAAC,KAAK,CACnB,0EAA0E,EAC1E,KAAK,CACN,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,eAAe;IACb,mBAAmB;CACpB,CAAC","sourcesContent":["import RemoteLogging, { LogEntryFields, LogLevel } from './RemoteLogging';\n\n/**\n * Creates a console object that delegates calls to the specified underlying console and also sends\n * the messages to the development environment over a remote connection.\n */\nfunction createRemoteConsole(originalConsole: Console): Console {\n let groupDepth = 0;\n\n const enhancedConsole: typeof originalConsole = Object.create(originalConsole);\n\n // https://console.spec.whatwg.org/#debug\n // Don't use a level below \"info\" because \"debug\" is intended for messages that shouldn't be shown\n // to the developer\n _defineConsoleLogMethod('debug', 'info');\n\n // https://console.spec.whatwg.org/#log\n _defineConsoleLogMethod('log', 'info');\n\n // https://console.spec.whatwg.org/#info\n _defineConsoleLogMethod('info', 'info');\n\n // https://console.spec.whatwg.org/#warn\n _defineConsoleLogMethod('warn', 'warn');\n\n // https://console.spec.whatwg.org/#error\n _defineConsoleLogMethod('error', 'error');\n\n // https://console.spec.whatwg.org/#assert\n enhancedConsole.assert = function assert(condition: unknown, ...data: unknown[]): void {\n if (originalConsole.assert) {\n // @ts-ignore\n originalConsole.assert(!!condition, ...data);\n }\n\n if (condition) {\n return;\n }\n\n const assertionMessage = 'Assertion failed';\n if (!data.length) {\n data.push(assertionMessage);\n } else {\n if (typeof data[0] !== 'string') {\n data.unshift(assertionMessage);\n } else {\n data[0] = `${assertionMessage}: ${data[0]}`;\n }\n }\n\n _enqueueRemoteLog('error', {}, data);\n };\n\n // https://console.spec.whatwg.org/#group\n enhancedConsole.group = function group(...data: unknown[]): void {\n if (originalConsole.group) {\n // @ts-ignore\n originalConsole.group(...data);\n }\n\n _enqueueRemoteLog('info', {}, data);\n groupDepth++;\n };\n\n // https://console.spec.whatwg.org/#groupcollapsed\n enhancedConsole.groupCollapsed = function groupCollapsed(...data: unknown[]): void {\n if (originalConsole.groupCollapsed) {\n // @ts-ignore\n originalConsole.groupCollapsed(...data);\n }\n\n _enqueueRemoteLog('info', { groupCollapsed: true }, data);\n groupDepth++;\n };\n\n // https://console.spec.whatwg.org/#groupend\n enhancedConsole.groupEnd = function groupEnd(): void {\n if (originalConsole.groupEnd) {\n originalConsole.groupEnd();\n }\n\n if (groupDepth > 0) {\n groupDepth--;\n }\n\n _enqueueRemoteLog('info', { shouldHide: true }, []);\n };\n\n /**\n * Defines a method in the `console.log()` family on the enhanced console\n * instance\n */\n function _defineConsoleLogMethod(name: keyof typeof console, level: LogLevel): void {\n enhancedConsole[name] = function __expoConsoleLog(...data: unknown[]): void {\n const originalMethod = originalConsole[name];\n if (typeof originalMethod === 'function') {\n originalMethod.apply(originalConsole, data);\n }\n\n _enqueueRemoteLog(level, {}, data);\n };\n }\n\n /**\n * Schedules the given log entry to be sent remotely in a safe way that handles all errors. This\n * function is responsible for error handling because the console methods are synchronous but\n * sending log messages is asynchronous, so this code (instead of the console methods) needs to be\n * responsible for asynchronous errors.\n */\n function _enqueueRemoteLog(\n level: LogLevel,\n additionalFields: LogEntryFields,\n data: unknown[]\n ): void {\n RemoteLogging.enqueueRemoteLogAsync(level, { groupDepth, ...additionalFields }, data).catch(\n error => {\n originalConsole.error(\n `There was a problem sending log messages to your development environment`,\n error\n );\n }\n );\n }\n\n return enhancedConsole;\n}\n\nexport default {\n createRemoteConsole,\n};\n"]}
\No newline at end of file