MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / consoleSandbox

Function consoleSandbox

packages/core/src/utils/debug-logger.ts:45–70  ·  view source on GitHub ↗
(callback: () => T)

Source from the content-addressed store, hash-verified

43 * @returns The results of the callback
44 */
45export function consoleSandbox<T>(callback: () => T): T {
46 if (!('console' in GLOBAL_OBJ)) {
47 return callback();
48 }
49
50 const console = GLOBAL_OBJ.console;
51 const wrappedFuncs: Partial<Record<ConsoleLevel, (...args: unknown[]) => void>> = {};
52
53 const wrappedLevels = Object.keys(originalConsoleMethods) as ConsoleLevel[];
54
55 // Restore all wrapped console methods
56 wrappedLevels.forEach(level => {
57 const originalConsoleMethod = originalConsoleMethods[level];
58 wrappedFuncs[level] = console[level] as (...args: unknown[]) => void;
59 console[level] = originalConsoleMethod as (...args: unknown[]) => void;
60 });
61
62 try {
63 return callback();
64 } finally {
65 // Revert restoration to wrapped state
66 wrappedLevels.forEach(level => {
67 console[level] = wrappedFuncs[level] as (...args: unknown[]) => void;
68 });
69 }
70}
71
72function enable(): void {
73 _getLoggerSettings().enabled = true;

Callers 15

integration.tsFile · 0.90
initFunction · 0.90
initFunction · 0.90
sentryFunction · 0.90
handleErrorMethod · 0.90
addBreadcrumbFunction · 0.90
initAndBindFunction · 0.90
_INTERNAL_captureLogFunction · 0.90
dsnFromStringFunction · 0.90
showSpanDropWarningFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90

Calls 3

keysMethod · 0.65
forEachMethod · 0.65
callbackFunction · 0.50

Tested by

no test coverage detected