user-facing CLI command
(
server: &str,
name: &str,
lines: u32,
tail: bool,
since: Option<&str>,
sources: &[String],
level: &str,
tls: &TlsOptions,
)
| 7393 | |
| 7394 | #[allow(clippy::too_many_arguments)] // user-facing CLI command |
| 7395 | pub async fn sandbox_logs( |
| 7396 | server: &str, |
| 7397 | name: &str, |
| 7398 | lines: u32, |
| 7399 | tail: bool, |
| 7400 | since: Option<&str>, |
| 7401 | sources: &[String], |
| 7402 | level: &str, |
| 7403 | tls: &TlsOptions, |
| 7404 | ) -> Result<()> { |
| 7405 | let mut client = grpc_client(server, tls).await?; |
| 7406 | |
| 7407 | // Resolve sandbox name to id. |
| 7408 | let sandbox = client |
| 7409 | .get_sandbox(GetSandboxRequest { |
| 7410 | name: name.to_string(), |
| 7411 | }) |
| 7412 | .await |
| 7413 | .into_diagnostic()? |
| 7414 | .into_inner() |
| 7415 | .sandbox |
| 7416 | .ok_or_else(|| miette::miette!("sandbox not found"))?; |
| 7417 | |
| 7418 | // Normalize "all" to empty list (server treats empty as "no filter"). |
| 7419 | let source_filter: Vec<String> = sources |
| 7420 | .iter() |
| 7421 | .filter(|s| s.as_str() != "all") |
| 7422 | .cloned() |
| 7423 | .collect(); |
| 7424 | |
| 7425 | let since_ms = if let Some(s) = since { |
| 7426 | let dur_ms = parse_duration_to_ms(s)?; |
| 7427 | let now_ms = i64::try_from( |
| 7428 | std::time::SystemTime::now() |
| 7429 | .duration_since(std::time::UNIX_EPOCH) |
| 7430 | .into_diagnostic()? |
| 7431 | .as_millis(), |
| 7432 | ) |
| 7433 | .into_diagnostic()?; |
| 7434 | now_ms - dur_ms |
| 7435 | } else { |
| 7436 | 0 |
| 7437 | }; |
| 7438 | |
| 7439 | if tail { |
| 7440 | // Streaming mode: use WatchSandbox. |
| 7441 | let mut stream = client |
| 7442 | .watch_sandbox(WatchSandboxRequest { |
| 7443 | id: sandbox.object_id().to_string(), |
| 7444 | follow_status: false, |
| 7445 | follow_logs: true, |
| 7446 | follow_events: false, |
| 7447 | log_tail_lines: lines, |
| 7448 | event_tail: 0, |
| 7449 | stop_on_terminal: false, |
| 7450 | log_since_ms: since_ms, |
| 7451 | log_sources: source_filter, |
| 7452 | log_min_level: level.to_uppercase(), |
no test coverage detected