Commit fe7ef63
authored
feat(cli): Add initial event logging system (#43013)
# Why
Based on / Supersedes #42249
We should be able to log JSONL events and capture them for debugging. In
theory, most places that receive/send events, or that have `debug` calls
that are ultimately useful to be surfaced in non-terminal environments
or when more output is needed should have event calls.
In the future, we may be able to add the `profiler` system to this as
well, and be able to fork performance-relevant data (e.g. performance
marks and profiler outputs) out of the event system.
As a proof of concept, this ports the `MetroTerminalReporter` events to
the new system (with new requirements applied)
# How
**Base Requirements:**
- should be able to write to file descriptors (compatible with both unix
sockets and files/streams), and to file paths
- shouldn't slow down the runtime of the CLI by much more than the cost
to stringify JSONL events
- should be able to define types ahead of time and collect them in one
place
Most events we want to capture can be captured rapidly (we shouldn't
care too much about how many events we log), and we should keep
pre-processing to a minimum to allow the event system to always be
active without much overhead.
The stream that we're writing with is similar to `FastUtf8Stream` /
`SonicBoom` and is non-blocking. Flushing is avoided to keep performance
high.
- Implement non-blocking `LogStream`
- Add `installEventLogger` to entrypoint
- protects stdout/stderr when logger is active on one of them)
- Add `events('category')` helper to create structured log events
- Add logger to `MetroTerminalReporter` to demonstrate usage
- Clean up calls in `MetroTerminalReporter` and pass sanitized data to
event logger
- Add `shouldReduceLogs` helper and disable bundling progress when
headless is active and event logger is used
- **Drive-by fix:** Rename `projectRoot` variable in
`MetroTerminalReporter` to `serverRoot` to reflect its actual path
# Test Plan
Verify that metro events are logged:
- Run `LOG_EVENTS=events.log expo start` and check `events.log`
- Run `LOG_EVENTS=1 expo start` and check standard output
# Checklist
<!--
Please check the appropriate items below if they apply to your diff.
-->
- [x] I added a `changelog.md` entry and rebuilt the package sources
according to [this short
guide](https://github.com/expo/expo/blob/main/CONTRIBUTING.md#-before-submitting)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)1 parent d02129a commit fe7ef63
10 files changed
Lines changed: 1335 additions & 102 deletions
File tree
- packages/@expo/cli
- bin
- src
- events
- __tests__
- start/server/metro
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
141 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
142 | 178 | | |
143 | 179 | | |
144 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
7 | 13 | | |
8 | 14 | | |
9 | 15 | | |
| |||
0 commit comments