Skip to content

Commit 4ee40de

Browse files
author
Luca Forstner
committed
Try fix error more?
1 parent 3bdd030 commit 4ee40de

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/utils/src/logger.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { WrappedFunction } from '@sentry/types';
22

33
import { getGlobalObject, getGlobalSingleton } from './global';
44

5-
// TODO: Implement different loggers for different environments
6-
const global = getGlobalObject<Window | NodeJS.Global>();
7-
85
/** Prefix for logging strings */
96
const PREFIX = 'Sentry Logger ';
107

@@ -26,21 +23,21 @@ interface Logger extends LoggerConsoleMethods {
2623
* @returns The results of the callback
2724
*/
2825
export function consoleSandbox<T>(callback: () => T): T {
29-
const global = getGlobalObject<Window>();
26+
const globalObject = getGlobalObject<Window>();
3027

31-
if (!('console' in global)) {
28+
if (!('console' in globalObject)) {
3229
return callback();
3330
}
3431

35-
const originalConsole = global.console as Console & Record<string, unknown>;
32+
const originalConsole = globalObject.console as Console & Record<string, unknown>;
3633
const wrappedLevels: Partial<LoggerConsoleMethods> = {};
3734

3835
// Restore all wrapped console methods
3936
CONSOLE_LEVELS.forEach(level => {
4037
// TODO(v7): Remove this check as it's only needed for Node 6
4138
const originalWrappedFunc =
4239
originalConsole[level] && (originalConsole[level] as WrappedFunction).__sentry_original__;
43-
if (level in global.console && originalWrappedFunc) {
40+
if (level in globalObject.console && originalWrappedFunc) {
4441
wrappedLevels[level] = originalConsole[level] as LoggerConsoleMethods[typeof level];
4542
originalConsole[level] = originalWrappedFunc as Console[typeof level];
4643
}
@@ -57,6 +54,9 @@ export function consoleSandbox<T>(callback: () => T): T {
5754
}
5855

5956
function makeLogger(): Logger {
57+
// TODO: Implement different loggers for different environments
58+
const globalObject = getGlobalObject<Window | NodeJS.Global>();
59+
6060
let enabled = false;
6161
const logger: Partial<Logger> = {
6262
enable: () => {
@@ -73,7 +73,7 @@ function makeLogger(): Logger {
7373
logger[name] = (...args: any[]) => {
7474
if (enabled) {
7575
consoleSandbox(() => {
76-
global.console[name](`${PREFIX}[${name}]:`, ...args);
76+
globalObject.console[name](`${PREFIX}[${name}]:`, ...args);
7777
});
7878
}
7979
};

0 commit comments

Comments
 (0)