(
mut child: Child,
stdout: ChildStdout,
state: Arc<LogStreamState>,
)
| 170 | } |
| 171 | |
| 172 | async fn read_log_stream( |
| 173 | mut child: Child, |
| 174 | stdout: ChildStdout, |
| 175 | state: Arc<LogStreamState>, |
| 176 | ) -> Result<(), String> { |
| 177 | let mut lines = BufReader::new(stdout).lines(); |
| 178 | while let Some(line) = lines.next_line().await.map_err(|error| error.to_string())? { |
| 179 | let Some(entry) = parse_log_entry(&line) else { |
| 180 | continue; |
| 181 | }; |
| 182 | |
| 183 | let mut entries = state.entries.lock().await; |
| 184 | entries.push_back(entry); |
| 185 | while entries.len() > MAX_LOG_ENTRIES { |
| 186 | entries.pop_front(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if matches!(child.try_wait(), Ok(None)) { |
| 191 | let _ = child.kill().await; |
| 192 | } |
| 193 | let _ = child.wait().await; |
| 194 | Ok(()) |
| 195 | } |
| 196 | |
| 197 | fn parse_log_entry(line: &str) -> Option<LogEntry> { |
| 198 | let trimmed = line.trim(); |
no test coverage detected