Skip to content

Commit e26a153

Browse files
v0.7.1: background log capture for every running container (#103)
* history: per-run log counters written in the same transaction as rows Add log_runs (persisted_lines, complete) and a nullable container_logs.started_at, migrated in place from v0.7.0 databases. The batched writer bumps the run counter in the same transaction as the inserted rows. Add runtime::run_info (inspect). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * logpersist: background log supervisor driven by the poll tick Replace the per-view persisting follower with a supervisor that keeps one resumable 'logs -f' follower per running container (cap 32) and one-shot catch-ups for stopped runs, resuming exactly from log_runs counters. Display streams no longer persist. New 'backgroundLogs' pref (default on) applied live through save_prefs; Doctor reports followed containers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * settings: Save container logs in the background switch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * live tests: background log capture (a-e), replacing the per-view test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(live): retry the first-poll CPU check under parallel container churn Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c85703d commit e26a153

16 files changed

Lines changed: 1744 additions & 268 deletions

File tree

‎app/src-tauri/src/commands.rs‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ static LOG_STREAMS: LazyLock<LogStreams> = LazyLock::new(LogStreams::default);
649649
/// should also call `history::flush_logs`).
650650
pub fn stop_all_log_streams() {
651651
LOG_STREAMS.stop_all();
652-
crate::logpersist::stop_all();
653652
}
654653

655654
/// Stream ids become part of an event name, which Tauri restricts to
@@ -665,7 +664,6 @@ fn valid_stream_id(id: &str) -> bool {
665664
#[tauri::command]
666665
pub fn stop_log_stream(stream_id: String) {
667666
LOG_STREAMS.stop(&stream_id);
668-
crate::logpersist::stop_owner(&stream_id);
669667
}
670668

671669
#[tauri::command]
@@ -716,15 +714,9 @@ pub async fn start_log_stream(
716714
let argv_ref: Vec<&str> = argv.iter().map(String::as_str).collect();
717715
let child = runtime::spawn(&argv_ref).map_err(err_str)?;
718716
let app2 = app.clone();
719-
let id_for_persist = id.clone();
720717
let sid = stream_id.clone();
721-
// Boot logs are VM console output, not container stdio — don't mix
722-
// them into the per-container log history sidecar.
723-
let persist = !boot.unwrap_or(false);
724-
// The display stream replays the log on every open, so it never
725-
// persists; a separate follower owned by this stream does (see
726-
// logpersist.rs).
727-
let sid_persist = stream_id.clone();
718+
// Display only: persistence is owned by the background supervisor
719+
// (logpersist.rs), which also never stores boot logs.
728720
// Hold the registry lock across spawn+insert so a stream that ends
729721
// instantly can't call finish() before it is registered (which would
730722
// leave a stale entry behind).
@@ -738,15 +730,9 @@ pub async fn start_log_stream(
738730
.await;
739731
let _ = app.emit(&event, "[follow ended]".to_string());
740732
LOG_STREAMS.finish(&sid);
741-
crate::logpersist::stop_owner(&sid);
742733
});
743734
LogStreams::register(&mut streams, stream_id, task.abort_handle());
744735
}
745-
if persist {
746-
if let Err(e) = crate::logpersist::start(&sid_persist, &id_for_persist).await {
747-
eprintln!("log persistence not started for {id_for_persist}: {e:#}");
748-
}
749-
}
750736
Ok(())
751737
}
752738

@@ -858,6 +844,9 @@ pub fn save_prefs(app: tauri::AppHandle, mut prefs: Prefs) -> Result<(), String>
858844
prefs.save().map_err(err_str)?;
859845
// Apply menubar mode live (close behaviour + Dock icon), no restart.
860846
crate::set_menubar_mode(&app, prefs.menubar_mode);
847+
// Likewise the background log capture switch: starts/stops followers
848+
// without a restart (the next poll tick reconciles).
849+
crate::set_background_logs(prefs.background_logs);
861850
Ok(())
862851
}
863852

‎app/src-tauri/src/doctor.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,23 @@ pub async fn run() -> Vec<DoctorCheck> {
152152
out.push(warn(format!("runtime API socket not found at {sock}")));
153153
}
154154

155+
// 9. background log capture (see logpersist.rs).
156+
out.push(log_capture_check(crate::logpersist::status()));
157+
155158
out
156159
}
157160

161+
fn log_capture_check(s: crate::logpersist::Status) -> DoctorCheck {
162+
if !s.enabled {
163+
return ok("background log capture: off (Settings → Save container logs)".into());
164+
}
165+
ok(format!(
166+
"background log capture: {} container{} followed",
167+
s.followers,
168+
if s.followers == 1 { "" } else { "s" }
169+
))
170+
}
171+
158172
/// Error check when the CLI is older than the supported minimum. None when
159173
/// it's fine (or the version couldn't be parsed; the `--version` row
160174
/// already shows the raw output).
@@ -228,6 +242,25 @@ fn config_path(name: &str) -> Option<PathBuf> {
228242
mod tests {
229243
use super::*;
230244

245+
#[test]
246+
fn log_capture_line_reports_follower_count_or_off() {
247+
use crate::logpersist::Status;
248+
let s = |enabled, followers| Status {
249+
enabled,
250+
followers,
251+
catching_up: 0,
252+
};
253+
assert_eq!(
254+
log_capture_check(s(true, 1)).text,
255+
"background log capture: 1 container followed"
256+
);
257+
assert_eq!(
258+
log_capture_check(s(true, 3)).text,
259+
"background log capture: 3 containers followed"
260+
);
261+
assert!(log_capture_check(s(false, 0)).text.contains("off"));
262+
}
263+
231264
#[test]
232265
fn mismatch_warns_with_restart_fix() {
233266
let c = version_mismatch_check(Some("1.7.1"), Some("1.4.1")).unwrap();

0 commit comments

Comments
 (0)