|
1 |
| -function isMethodAllowed(method) { |
2 |
| - |
3 |
| - const allowedMethodsEnv = process.env.REACT_APP_CONSOLE_TYPES?.split(',') || []; |
4 |
| - const methodCategories = { |
5 |
| - log: 'info', |
6 |
| - info: 'info', |
7 |
| - warn: 'warn', |
8 |
| - error: 'error', |
9 |
| - assert: 'error' |
10 |
| - }; |
11 |
| - |
12 |
| - return allowedMethodsEnv.includes(methodCategories[method]); |
13 |
| -} |
| 1 | +//ConsoleBehavior.js |
14 | 2 |
|
15 | 3 | function ConsoleBehavior() {
|
16 |
| - const originalConsole = { ...console }; |
17 |
| - |
18 |
| - const originalPrepareStackTrace = Error.prepareStackTrace; |
19 |
| - |
20 |
| - Object.keys(console).forEach(method => { |
21 |
| - if (typeof console[method] === 'function') { |
22 |
| - console[method] = (...args) => { |
23 |
| - if (isMethodAllowed(method)) { |
24 |
| - Error.prepareStackTrace = (_, stack) => stack; |
25 |
| - const stack = new Error().stack; |
26 |
| - Error.prepareStackTrace = originalPrepareStackTrace; |
27 |
| - |
28 |
| - const callSite = stack[1]; |
29 |
| - if (callSite) { |
30 |
| - const fileName = callSite.getFileName(); |
31 |
| - const lineNumber = callSite.getLineNumber(); |
32 |
| - args.push(`(at ${fileName}:${lineNumber})`); |
33 |
| - } |
34 |
| - |
35 |
| - originalConsole[method].apply(console, args); |
36 |
| - } |
37 |
| - }; |
38 |
| - } |
39 |
| - }); |
| 4 | + // If displayConsole is undefined, proceed as true |
| 5 | + const displayConsole = process.env.REACT_APP_DISPLAY_CONSOLE; |
| 6 | + |
| 7 | + if (displayConsole === 'false') { |
| 8 | + Object.keys(console).forEach(method => { |
| 9 | + if (typeof console[method] === 'function') { |
| 10 | + console[method] = () => { }; |
| 11 | + } |
| 12 | + }); |
| 13 | + } |
40 | 14 | }
|
41 | 15 |
|
42 | 16 | export default ConsoleBehavior;
|
0 commit comments