diff --git a/packages/integrations/src/captureconsole.ts b/packages/integrations/src/captureconsole.ts index 3f9076fd7293..59a5cec99fd4 100644 --- a/packages/integrations/src/captureconsole.ts +++ b/packages/integrations/src/captureconsole.ts @@ -1,5 +1,5 @@ import { EventProcessor, Hub, Integration } from '@sentry/types'; -import { fill, getGlobalObject, safeJoin, severityFromString } from '@sentry/utils'; +import { CONSOLE_LEVELS, fill, getGlobalObject, safeJoin, severityFromString } from '@sentry/utils'; const global = getGlobalObject(); @@ -18,7 +18,7 @@ export class CaptureConsole implements Integration { /** * @inheritDoc */ - private readonly _levels: string[] = ['log', 'info', 'warn', 'error', 'debug', 'assert']; + private readonly _levels: string[] = CONSOLE_LEVELS; /** * @inheritDoc diff --git a/packages/utils/src/instrument.ts b/packages/utils/src/instrument.ts index 985df7c09bb4..2276a4877999 100644 --- a/packages/utils/src/instrument.ts +++ b/packages/utils/src/instrument.ts @@ -6,7 +6,7 @@ import { WrappedFunction } from '@sentry/types'; import { isDebugBuild } from './env'; import { getGlobalObject } from './global'; import { isInstanceOf, isString } from './is'; -import { logger } from './logger'; +import { CONSOLE_LEVELS, logger } from './logger'; import { fill } from './object'; import { getFunctionName } from './stacktrace'; import { supportsHistory, supportsNativeFetch } from './supports'; @@ -110,7 +110,7 @@ function instrumentConsole(): void { return; } - ['debug', 'info', 'warn', 'error', 'log', 'assert'].forEach(function (level: string): void { + CONSOLE_LEVELS.forEach(function (level: string): void { if (!(level in global.console)) { return; } diff --git a/packages/utils/src/logger.ts b/packages/utils/src/logger.ts index a6f5e41a9072..1913916686b5 100644 --- a/packages/utils/src/logger.ts +++ b/packages/utils/src/logger.ts @@ -10,6 +10,8 @@ const global = getGlobalObject(); /** Prefix for logging strings */ const PREFIX = 'Sentry Logger '; +export const CONSOLE_LEVELS = ['debug', 'info', 'warn', 'error', 'log', 'assert']; + /** JSDoc */ interface ExtensibleConsole extends Console { [key: string]: any; @@ -24,7 +26,6 @@ interface ExtensibleConsole extends Console { */ export function consoleSandbox(callback: () => any): any { const global = getGlobalObject(); - const levels = ['debug', 'info', 'warn', 'error', 'log', 'assert']; if (!('console' in global)) { return callback(); @@ -35,7 +36,7 @@ export function consoleSandbox(callback: () => any): any { const wrappedLevels: { [key: string]: any } = {}; // Restore all wrapped console methods - levels.forEach(level => { + CONSOLE_LEVELS.forEach(level => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (level in (global as any).console && (originalConsole[level] as WrappedFunction).__sentry_original__) { wrappedLevels[level] = originalConsole[level] as WrappedFunction;