Skip to content

feat(logging): add size-limited log rotation via lumberjack#1401

Draft
adamshiervani wants to merge 1 commit into
devfrom
feat/log-rotation
Draft

feat(logging): add size-limited log rotation via lumberjack#1401
adamshiervani wants to merge 1 commit into
devfrom
feat/log-rotation

Conversation

@adamshiervani
Copy link
Copy Markdown
Contributor

Summary

  • Add lumberjack-based log rotation to prevent unbounded last.log growth on long-running devices
  • App now writes directly to /userdata/jetkvm/app.log (50 MB max, 1 backup) via a new zerolog multi-writer, independent of the shell redirect in RkLunch.sh
  • Log app and system version at startup using NoLevel so it always appears regardless of configured log level

Background

/userdata/jetkvm/last.log grows unbounded for the lifetime of a process run — the only reset is a process restart (shell > truncation). On a device that stays up for months, this can consume significant space on the 13 GB /userdata partition.

The rv1106-system image and the app have independent update paths, so we can't guarantee the shell redirect will be removed when the app is updated. This solution writes to a different file (app.log), making it safe regardless of whether the old redirect is still in place.

Changes

File Change
go.mod / go.sum Add gopkg.in/natefinch/lumberjack.v2
internal/logging/logger.go Add lumberjack writer to multi-writer (guarded: only on device)
internal/supervisor/consts.go AppLogPath/userdata/jetkvm/app.log
main.go Version log changed from Info() to Log() (NoLevel)
ui/e2e/global-teardown.ts Read app.log instead of last.log
ui/e2e/helpers.ts restartAppViaSSH redirects to /dev/null
ui/e2e/log-rotation.spec.ts New e2e tests for log rotation
DEVELOPMENT.md Updated all log path references

Test plan

  • Deploy to device, verify /userdata/jetkvm/app.log is created and contains log output
  • Verify app.log contains app_version and system_version fields
  • Verify diagnostics zip (GET /diagnostics) includes app.log
  • Verify tail -f /userdata/jetkvm/app.log works for live log viewing
  • On a device with old system image (redirect still in place), verify both last.log and app.log are written — app.log is authoritative
  • Run e2e tests: npx playwright test log-rotation

Add lumberjack-based log rotation to prevent unbounded growth of the
application log file on long-running devices. The app now writes to
/userdata/jetkvm/app.log (managed, 50MB max, 1 backup) instead of
relying solely on the shell redirect to last.log.

This works safely regardless of whether the rv1106-system shell
redirect is updated: lumberjack writes to a different file path,
so the old redirect to last.log is harmless.

Also log app and system version at startup using NoLevel so it
always appears regardless of configured log level.
terryrankine added a commit to terryrankine/kvm that referenced this pull request May 7, 2026
Add rotating file output to zerolog via gopkg.in/natefinch/lumberjack.v2.
Writes to /userdata/picokvm/app.log (fork path; upstream uses jetkvm/).
50 MB max size, 1 backup retained, no compression.

The directory guard (os.Stat) silently skips the file writer when the
data directory does not exist, so the binary continues to work on dev
hosts where the path is absent.

Also change the startup version-banner to logger.Log() (no level) so it
is always written regardless of the configured log level.

- internal/logging/logger.go: AppLogPath constant, newDefaultLogOutput(),
  replace MultiLevelWriter init with function call
- main.go: logger.Info() → logger.Log() for startup banner
- go.mod/go.sum: add gopkg.in/natefinch/lumberjack.v2 v2.2.1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant