Skip to content

fix(daemon): rotate dashboard.log on start instead of truncating#204

Draft
esphbot wants to merge 1 commit into
esphome:mainfrom
esphbot:koan/203-rotate-dashboard-log
Draft

fix(daemon): rotate dashboard.log on start instead of truncating#204
esphbot wants to merge 1 commit into
esphome:mainfrom
esphbot:koan/203-rotate-dashboard-log

Conversation

@esphbot

@esphbot esphbot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

Rotate dashboard.log on backend start instead of truncating it, keeping the last 3 runs (dashboard.log.1...3).

Why

dashboard.log was opened with File::create on every backend start (daemon/mod.rs), which truncates. Each app launch or backend restart wiped the previous run's logs. Issue #203 reports a macOS self-update restart where the dashboard comes back unreachable as a remote build server — and the only available log is "truncated on every startup," so there's nothing to inspect at the exact moment it's needed.

How

  • New util::rotate_log(path, keep) — best-effort, dependency-free numbered rotation (pathpath.1 → … → path.{keep}, oldest discarded). No-op on first run / keep == 0.
  • daemon::start() rotates before File::create; a rotation failure logs a warning and start proceeds (losing old logs must never block the backend). The tray "View Logs" entry opens this folder, so retained runs are browsable.

Scope: this addresses the log-truncation half of #203. The primary "restart comes back unreachable" symptom is the backend's mDNS/port release timing on relaunch — the same class redirected upstream as device-builder#1642; I deliberately did not add a launcher-side process gate for it (see PR #202's outcome). Rotated logs are precisely what's needed to confirm that diagnosis from a user's machine.

App-level (tracing) file logging — the other thing #203 asks for — is a larger change (the subscriber inits before the data dir is resolved) and is left as a follow-up.

Testing

  • 5 new unit tests for rotate_log (first-run no-op, single shift, multi-run history ordering + oldest discarded, keep == 0).
  • No local Rust toolchain available here — relying on CI for cargo test/clippy/cross-platform build.

Quality Report

Changes: 2 files changed, 119 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (67 passed)

Branch hygiene: clean

Generated by Kōan

dashboard.log was opened with File::create on every backend start, which
truncates it — so each app launch or backend restart wiped the previous
run's logs. After a failed self-update restart (issue esphome#203) there was
nothing left to inspect, exactly when the logs matter most.

Rotate the prior dashboard.log to numbered backups (dashboard.log.1..3)
before creating a fresh one. Best-effort: a rotation failure logs a
warning and start proceeds, since losing old logs must never block the
backend. The tray "View Logs" entry opens this folder, so the retained
runs are directly browsable.
@esphome

esphome Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

The following artifacts are available from this build:

Windows

Linux

macOS

Note

These macOS builds are not signed or notarized, so Gatekeeper will refuse to open them. To run one, download the dmg, then re-sign it locally with the helper script from this repo. It needs no Apple certificate; by default it applies an ad-hoc signature that lets the app open on your own machine. No local clone required — download the script and run it directly:

curl -fsSL https://raw.githubusercontent.com/esphome/esphome-desktop/main/build-scripts/sign_macos_local.sh -o sign_macos_local.sh
bash sign_macos_local.sh ~/Downloads/the-downloaded.dmg

Mount the resulting *-signed.dmg, drag the app to Applications, and it will open. Pass --help for Developer ID signing and other options.


Last updated: 2b04e4c - Run #545 - 2026-06-22 05:10:56 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants