react-native-debug-toolkit 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,40 +5,26 @@ const originalConsole = {}; // Store original console methods
|
|
|
5
5
|
const _interceptConsole = () => {
|
|
6
6
|
const levels = ['log', 'info', 'warn', 'error'];
|
|
7
7
|
levels.forEach(level => {
|
|
8
|
-
if (typeof console[level] === 'function') {
|
|
9
|
-
originalConsole[level] = console[level]; // Store original
|
|
8
|
+
if (typeof console[level] === 'function') { // Check if it's actually a function
|
|
9
|
+
originalConsole[level] = console[level]; // Store original
|
|
10
10
|
|
|
11
11
|
console[level] = (...args) => {
|
|
12
|
-
//
|
|
12
|
+
// Call original console method first
|
|
13
|
+
originalConsole[level].apply(console, args); // Use apply for proper context
|
|
14
|
+
|
|
15
|
+
// Add log entry
|
|
13
16
|
if (logs.length >= MAX_LOGS) {
|
|
14
|
-
logs.shift();
|
|
17
|
+
logs.shift(); // Remove the oldest log if limit is reached
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (arg instanceof Error) return `Error: ${arg.message}${arg.stack ? `\n${arg.stack}` : ''}`;
|
|
19
|
-
if (arg instanceof Promise) return '[Promise]';
|
|
20
|
-
if (typeof arg === 'function') return '[Function]';
|
|
21
|
-
if (typeof arg === 'object' && arg !== null) {
|
|
22
|
-
try { return JSON.stringify(arg); } catch (e) { return '[Object - Cannot Serialize]'; }
|
|
23
|
-
}
|
|
24
|
-
return arg;
|
|
25
|
-
});
|
|
19
|
+
|
|
20
|
+
// Store log data
|
|
26
21
|
logs.push({
|
|
27
22
|
timestamp: new Date(),
|
|
28
23
|
level: level,
|
|
29
|
-
data:
|
|
24
|
+
data: args, // Store all arguments passed to console[level]
|
|
30
25
|
});
|
|
31
|
-
// --- End Log Recording Logic ---
|
|
32
|
-
|
|
33
|
-
// --- Do NOT call the original console ---
|
|
34
|
-
// By omitting the following line, the intercepted log message (including
|
|
35
|
-
// the "Unhandled Promise Rejection" warning) will ONLY be stored
|
|
36
|
-
// in this feature's 'logs' array and will NOT be passed through
|
|
37
|
-
// to the standard developer console output (Metro, browser, etc.).
|
|
38
|
-
//
|
|
39
|
-
// originalConsole[level]?.apply(console, args);
|
|
40
26
|
|
|
41
|
-
// TODO: Notify UI if needed
|
|
27
|
+
// TODO: Notify UI if needed
|
|
42
28
|
};
|
|
43
29
|
}
|
|
44
30
|
});
|
package/package.json
CHANGED