|
1 | 1 | import { EventProcessor, Hub, Integration, Severity } from '@sentry/types';
|
2 |
| -import { getGlobalObject } from '@sentry/utils/misc'; |
3 |
| -import { fill, normalize } from '@sentry/utils/object'; |
4 |
| -import { safeJoin } from '@sentry/utils/string'; |
| 2 | +import { fill, getGlobalObject, normalize, safeJoin } from '@sentry/utils'; |
5 | 3 |
|
6 | 4 | const global = getGlobalObject<Window | NodeJS.Global>();
|
7 | 5 |
|
@@ -39,49 +37,46 @@ export class CaptureConsole implements Integration {
|
39 | 37 | return;
|
40 | 38 | }
|
41 | 39 |
|
42 |
| - this._levels.forEach(function(level: string): void { |
| 40 | + this._levels.forEach((level: string) => { |
43 | 41 | if (!(level in global.console)) {
|
44 | 42 | return;
|
45 | 43 | }
|
46 | 44 |
|
47 |
| - fill(global.console, level, function(originalConsoleLevel: () => any): any { |
48 |
| - // tslint:disable-next-line:only-arrow-functions |
49 |
| - return function(...args: any[]): any { |
50 |
| - const hub = getCurrentHub(); |
| 45 | + fill(global.console, level, (originalConsoleLevel: () => any) => (...args: any[]) => { |
| 46 | + const hub = getCurrentHub(); |
51 | 47 |
|
52 |
| - if (hub.getIntegration(CaptureConsole)) { |
53 |
| - hub.withScope(scope => { |
54 |
| - scope.setLevel(Severity.fromString(level)); |
55 |
| - scope.setExtra('arguments', normalize(args, 3)); |
56 |
| - scope.addEventProcessor(event => { |
57 |
| - event.logger = 'console'; |
58 |
| - if (event.sdk) { |
59 |
| - event.sdk = { |
60 |
| - ...event.sdk, |
61 |
| - integrations: [...(event.sdk.integrations || []), 'console'], |
62 |
| - }; |
63 |
| - } |
64 |
| - return event; |
65 |
| - }); |
| 48 | + if (hub.getIntegration(CaptureConsole)) { |
| 49 | + hub.withScope(scope => { |
| 50 | + scope.setLevel(Severity.fromString(level)); |
| 51 | + scope.setExtra('arguments', normalize(args, 3)); |
| 52 | + scope.addEventProcessor(event => { |
| 53 | + event.logger = 'console'; |
| 54 | + if (event.sdk) { |
| 55 | + event.sdk = { |
| 56 | + ...event.sdk, |
| 57 | + integrations: [...(event.sdk.integrations || []), 'console'], |
| 58 | + }; |
| 59 | + } |
| 60 | + return event; |
| 61 | + }); |
66 | 62 |
|
67 |
| - let message = safeJoin(args, ' '); |
68 |
| - if (level === 'assert') { |
69 |
| - if (args[0] === false) { |
70 |
| - message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`; |
71 |
| - scope.setExtra('arguments', normalize(args.slice(1), 3)); |
72 |
| - hub.captureMessage(message); |
73 |
| - } |
74 |
| - } else { |
| 63 | + let message = safeJoin(args, ' '); |
| 64 | + if (level === 'assert') { |
| 65 | + if (args[0] === false) { |
| 66 | + message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`; |
| 67 | + scope.setExtra('arguments', normalize(args.slice(1), 3)); |
75 | 68 | hub.captureMessage(message);
|
76 | 69 | }
|
77 |
| - }); |
78 |
| - } |
| 70 | + } else { |
| 71 | + hub.captureMessage(message); |
| 72 | + } |
| 73 | + }); |
| 74 | + } |
79 | 75 |
|
80 |
| - // this fails for some browsers. :( |
81 |
| - if (originalConsoleLevel) { |
82 |
| - Function.prototype.apply.call(originalConsoleLevel, global.console, args); |
83 |
| - } |
84 |
| - }; |
| 76 | + // this fails for some browsers. :( |
| 77 | + if (originalConsoleLevel) { |
| 78 | + Function.prototype.apply.call(originalConsoleLevel, global.console, args); |
| 79 | + } |
85 | 80 | });
|
86 | 81 | });
|
87 | 82 | }
|
|
0 commit comments