feat(log): the launcher's log kept in a file, with the run before, its crashes and what it did to the player's data #171
No reviewers
Labels
No labels
area/build
area/install
area/saves
area/tooling
area/ui
area/updates
ci: approved
good first issue
gpu/amd
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
platform/linux
platform/steam-deck
platform/windows
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/LongshotLauncher!171
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/LongshotLauncher:feat/launcher-log-file"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Player reports arrive with no launcher log: #146 ("deleted all saves"), #141 ("existing build not shown") and #152 ("exits with Unknown Hard Error") have only game logs, and the #146 reporter found no logs folder.
LauncherLogkept its lines in memory only and the launcher had no unhandled-exception handler, so a crash at start left nothing. Now the launcher keeps its log in a file, with the run before, its crashes, and what it did to the player's data.What changes
logs/launcher.login the launcher's home, plus the run before aslauncher.1.log, 1 MB per file. A shortcut's Play (--play, no window) appends toplay.logbeside it instead, so it never touches the file an open launcher is writing. Where:%LOCALAPPDATA%\LongshotLauncher\logs\launcher.log<exe folder>\LongshotLauncher-data\logs\launcher.log~/.local/share/longshot/launcher/logs/launcher.log(a portable AppImage:<AppImage>.home/logs/)LauncherLogalready records goes there with a timestamp, after a first line saying which launcher on which system. Every line has no user name (Privacy.Scrubfrom #164: the home folder as%USERPROFILE%or~, the name elsewhere in a path as<user>), including the lines that don't go throughAdd(the first line, a crash's stack). Links are logged without their query or fragment (LauncherLog.Link, where they are written;Addcuts any left over), so no signed download token is in memory, the file or a bug report. Each line goes at the file's end, so a line another launcher appended is never written over. Writing never throws into the app.ForgetGonedrops, builds.json and settings.json set aside, Free up space and the shader caches it clears, self-update steps (recover, rollback), install and uninstall.AppDomain.UnhandledException,TaskScheduler.UnobservedTaskExceptionand Avalonia's dispatcher write the exception before the process ends.launcher.logopens only after the instance lock, so--playor a second launcher never moves the running launcher's log aside. A crash with no file open (before the lock, or after the file stopped) is appended toplay.log. A start that hands over to the installed launcher appends rather than rolling, so the run before survives. Uninstall with data closes the file before deleting the home, and nothing is written after; "Run portable" reopens it in the new home.launcher.1.logandplay.logbeside it). README listslogs/.First lines, from the real writer:
Testing
Windows 11, .NET SDK 10.0.404.
python -I tests/test_launcher_core.py: 1634 checks pass. The check commit fails on main withA builds.json set aside is logged, with where it was kept:, and passes with the change.LauncherLogCheckscovers the file written with no user name, rolled over at the cap, the run before kept, a crash written once,play.logappended to and neverlauncher.log, a line another launcher appended kept whole, links cut (a decodedUri, a fragment), the saves gather logged, and a failing disk not throwing. Mutations of the fix (no seek to the end,Linkreturning the whole link, the crash going tolauncher.log, the gather line removed) each fail a check.JORDAN~1.DES) main itself fails a few checks.dotnet build: 0 errors, 0 warnings.Two cold reviews by a second agent (code only). The second approved; what each found is fixed in the
fix(log)commits.Not tested: the crash handlers firing in a real launcher, and
--playfrom a real shortcut (built, not run). The log stays on the PC; nothing sends it.🤖 Generated with Claude Code
Heads-up from #164 (#164): LauncherLog.Add now takes the OS user's name out of every line before it keeps it (Privacy.Scrub in Core/Privacy.cs: the home folder as ~, the name elsewhere in a path as [user]). If logs/launcher.log writes the lines Add keeps, this PR gets that for free. A writer that formats its own text before Add would need to call Privacy.Scrub itself. Whichever merges second rebases; LauncherLog.cs only changes in Add.
97a54bb6a486933390721be5dbcc7378d6b7a04dRebased onto main (after #164, #170, #175, #176, #178) and reworked after two cold reviews:
Add.LauncherLog.Linkwhere they are logged (scheme, host, port, path; no query, fragment oruser:password@). The old regex missed a decodedUriwith a space or quote in its query, and kept a query followed by#.Addcuts any query left over, so the bug report has none either.--playwriteslogs/play.log. It runs a saves gather and wrote nothing before; it never touches the open launcher'slauncher.log. A crash with no file open goes there too, with a line saying which process and version. Every line is written at the file's end.1634 checks pass on Windows; mutations of the fixes each fail a check.
Verdict: Approve. Until now a crash or a lost save left no launcher log anywhere. This gives the launcher a log file on disk, capped at 1 MB, with no user name and no signed link in it, and it costs nothing a player would notice. Nothing I found blocks it. Two follow-ups would make it say what its description says (see Suggestions).
The PR merged before this review was posted. The forge only takes reviews on open PRs, so this review is a comment, and the line notes are in the Suggestions list.
What it does for a player: when they report a crash at start, lost saves or a missing build, the launcher now has
logs/launcher.log(plus the run before it) showing what it did to their data and why it ended. The code gets better: the logging calls sit where the actions happen, and the file writer is one small class that never throws. The cost is one synchronous append under the existing lock per log line, and the launcher already makes very few lines.Reviewed:
78d6b7a04d(the head; the squash on main,029f025382, has the same tree) against7a4a61e7c9(fix(settings) from #170, the fork point). Read in full where they changed:Core/LauncherLog.cs,App/Program.cs(all ofMain,OpenLog,BecomePortable,Rollback,PlayWithoutWindow),App/App.axaml.cs,App/LauncherService.cs,Core/BugReport.cs,Core/BuildRegistry.cs,Core/Disk.cs,Core/Fetcher.cs,Core/Installer.cs,Core/LauncherSettings.cs,Core/Saves.cs,Core/SelfUpdate.cs,Core/ShaderCaches.cs,tests/launcher_core/LauncherLogChecks.cs, and theSavesChecksandProgramtest hooks. For context I also readCore/Privacy.csandLauncherLayout.OffersInstall. README was only skimmed. Nothing was run: this is a code review.Fixed in this review: nothing (the PR is merged).
Checked and fine:
Privacy.Scrub, including the header, the arguments and each line of a crash's stack (Clean). That covers the home folder, the user name anywhere in a path, and the Windows 8.3 short form (JORDAN~1). Links are logged throughLauncherLog.Link(no query, fragment oruser:password@), andNoQuerycuts any that slip past. NoLauncherLog.AddinCore/orApp/logs a raw URL. The saves gather logs paths, profile and slot folder names and the backup folder, never the contents of a save. The proxy line logsAuthority, which carries no credentials. No hostname or account name is logged apart from these.play.logis appended to and rolled only once it is past the cap.writer,written,nameandFilePathhappens undergate.FilePathis read without the lock, which is safe for a reference.Crashtakesgate, which is reentrant. A crash on the thread that holds it therefore goes through, because .NET runs the unhandled-exception event before that thread'sfinallyblocks unwind. A crash on another thread waits for a write that only waits on the disk. The whole ofCrashis in try/catch. The dispatcher sees the exception first and the process handler sees it again, andReferenceEqualswrites it only once. Neither handler marks the exception handled, so the launcher still ends exactly as before. ReportingUnobservedTaskExceptiondoesn't callSetObserved, so nothing changes there either.OpenLogcomes afterTakeLock, and every step inOpenFile,StartandWriteis in try/catch. A second launcher, or--play, never rolls the running launcher'slauncher.log. The hand-off starts (Install,OffersInstallwith a newer installed launcher) append instead of rolling. A self-update rolls the file in the new process while the old one holds it open, whichFileShare.Deleteallows on Windows and Linux allows anyway.CloseFilebeforeDeleteKeeping, andletGokeeps a later crash from making the deleted home again.Path.Combine, and the file is UTF-8 with no BOM. Both sides open it withFileShare.ReadWrite | Delete, which gives compatible advisory locks on Linux.play.log, a disk that fails), not the text of the code. The saves check reads the gather line from the realSaves.Gather.Suggestions (none of these block)
App/Program.cs:58and theRecover(own)at:49.--rollback, and the recovery from a leftover.old/.newat the top ofMain, both run beforeHomeandOpenLog, andCrashLogsis still null there. So the linesSelfUpdate.RollbackandRecovernow add (SelfUpdate.cs:92,:237,:247) stay in memory, and that process ends without writing them anywhere. The description lists "self-update steps (recover, rollback)" as logged, but only the laterRecover(current)is. A fix: resolve the home inRollback()and openplay.logthere (OpenLog(file: LauncherLog.PlayName)), asPlayWithoutWindowdoes.Core/LauncherLog.cs:206. Rolling over within a run moveslauncher.logontolauncher.1.log, so the run before is lost once this run passes 1 MB. The launcher writes few lines, so this is rare. If a later change logs more (unobserved tasks, each with its whole stack), keep the run before aslauncher.2.log, or roll within a run to a file of its own.Core/ShaderCaches.cs:204. Because the line is in afinally, it says "cleared: N files" even when a delete threw partway through.Disk.FreeWorksays "stopped … deleted:" in that case; this line could do the same.Testing: The author ran 1634 checks on Windows 11 and
dotnet build(0 warnings), and says mutations of the fixes each fail a check. CI's compile-and-test job was skipped, since it only runs on a manual dispatch. What's missing: a run on Linux, and any run of theApp/wiring the core checks can't reach. That means a real start, Install,--playfrom a shortcut, an update or rollback, and a crash handler firing. The description says these weren't run. They wouldn't hold the merge, because every path is wrapped in try/catch and can't change what the launcher does. A one-time look at a reallogs/folder after a Windows and a Linux start, before the stable release, would still be worth it.Overlaps and merge order: #182 and #183 (save restore and per-slot delete) change the player's saves and should log those steps the way this PR logs the gather. #42 (Send report) would send the bug report, which now names the log file's path (scrubbed). If it ever attaches the file itself, the scrubbing here is what keeps it private. No file conflicts.