Append one JSONL line to the env-configured RPC log. Logging must never break a request.
(&self, method: &str, handle: Option<&RepoHandle>)
| 357 | /// Append one JSONL line to the env-configured RPC log. Logging must |
| 358 | /// never break a request. |
| 359 | pub fn log_rpc(&self, method: &str, handle: Option<&RepoHandle>) { |
| 360 | let Some(path) = &self.log_path else { return }; |
| 361 | let record = serde_json::json!({ |
| 362 | "ts": std::time::SystemTime::now() |
| 363 | .duration_since(std::time::UNIX_EPOCH) |
| 364 | .map(|d| d.as_millis() as u64) |
| 365 | .unwrap_or(0), |
| 366 | "method": method, |
| 367 | "repository_id": handle.map(|h| data_encoding::HEXLOWER.encode(&h.repository_id()[..16])), |
| 368 | "root": handle.map(|h| h.root.display().to_string()), |
| 369 | }); |
| 370 | use std::io::Write; |
| 371 | if let Ok(mut file) = std::fs::OpenOptions::new() |
| 372 | .create(true) |
| 373 | .append(true) |
| 374 | .open(path) |
| 375 | { |
| 376 | let _ = writeln!(file, "{record}"); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | impl Default for DaemonState { |
no test coverage detected