| 34 | } |
| 35 | |
| 36 | pub fn read_all() -> Result<Vec<RuntimeEvent>> { |
| 37 | let data = match fs_err::read_to_string(RUNTIME_EVENT_LOG_FILE) { |
| 38 | Ok(data) => data, |
| 39 | Err(e) => { |
| 40 | if e.kind() == std::io::ErrorKind::NotFound { |
| 41 | return Ok(vec![]); |
| 42 | } |
| 43 | return Err(e).context("Failed to read user event log"); |
| 44 | } |
| 45 | }; |
| 46 | let mut event_logs = vec![]; |
| 47 | for line in data.lines() { |
| 48 | if line.trim().is_empty() { |
| 49 | continue; |
| 50 | } |
| 51 | let event_log = serde_json::from_str::<RuntimeEvent>(line) |
| 52 | .context("Failed to decode user event log")?; |
| 53 | event_logs.push(event_log); |
| 54 | } |
| 55 | Ok(event_logs) |
| 56 | } |
| 57 | |
| 58 | pub fn emit(&self) -> Result<()> { |
| 59 | let logline = serde_json::to_string(self).context("failed to serialize event log")?; |