forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.js
More file actions
90 lines (85 loc) · 2.2 KB
/
Logger.js
File metadata and controls
90 lines (85 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/
import {enableLogger} from 'react-devtools-feature-flags';
export type LoggerEvent =
| {
+event_name: 'loaded-dev-tools',
}
| {
+event_name: 'error',
+error_message: string | null,
+error_stack: string | null,
+error_component_stack: string | null,
}
| {
+event_name: 'selected-components-tab',
}
| {
+event_name: 'selected-profiler-tab',
}
| {
+event_name: 'load-hook-names',
+event_status: 'success' | 'error' | 'timeout' | 'unknown',
+duration_ms: number,
+inspected_element_display_name: string | null,
+inspected_element_number_of_hooks: number | null,
}
| {
+event_name: 'select-element',
+metadata: {
+source: string,
},
}
| {
+event_name: 'inspect-element-button-clicked',
}
| {
+event_name: 'profiling-start',
+metadata: {
+current_tab: string,
},
}
| {
+event_name: 'profiler-tab-changed',
+metadata: {
+tabId: string,
},
}
| {
+event_name: 'settings-changed',
+metadata: {
+key: string,
+value: any,
...
},
};
export type LogFunction = LoggerEvent => void | Promise<void>;
let logFunctions: Array<LogFunction> = [];
export const logEvent: LogFunction =
enableLogger === true
? function logEvent(event: LoggerEvent): void {
logFunctions.forEach(log => {
log(event);
});
}
: function logEvent() {};
export const registerEventLogger: (logFunction: LogFunction) => () => void =
enableLogger === true
? function registerEventLogger(logFunction: LogFunction): () => void {
if (enableLogger) {
logFunctions.push(logFunction);
return function unregisterEventLogger() {
logFunctions = logFunctions.filter(log => log !== logFunction);
};
}
return () => {};
}
: function registerEventLogger(logFunction: LogFunction) {
return () => {};
};