rayem1w on X (0.1.2330, macOS) was asked for ~/Library/Logs/magpie/serve.log while chasing a Codex "hit a snag" through the gateway, and had no such folder. Only the launch agent (magpie daemon install, written by launchd) and a gateway magpie tui left running wrote a log; the app opened from the Finder, the Dock or the Start menu logged to a stderr nobody reads, on every system. Now runGUI and runPanel (magpie, app, tray, panel, a window view, a magpie: link) call applog.Start before gui.Run. It sends the standard logger (the gateway, the plugin host, providers and Wails' error handler all log through it) to app.log as well as stderr, and points debug.SetCrashOutput at it so a panic's trace is there too: macOS ~/Library/Logs/magpie/app.log Windows %LOCALAPPDATA%\magpie\logs\app.log Linux $XDG_STATE_HOME/magpie/app.log, else ~/.local/state/magpie/app.log portable data/logs/app.log app.log, not serve.log: on a Mac launchd writes serve.log for the service, another process. The file is 0600. At 5 MiB it becomes app.old.log (two files at most); when another magpie (an update's new process) rotated it already, it is only opened again; when it can't be moved it is emptied. stderr goes first, through a writer that never fails, since io.MultiWriter stops at a failed writer and an app opened from Explorer has no stderr. Secrets: the log calls name header names and paths without queries; no key or token was found logged (grep of log.Print* in gateway, provider, plugin, gui, agent). scrub masks bearer/basic credentials, key/token query parameters and sk-, AIza, gh?_ and JWT shapes anyway. How a user finds it: Settings › About › Log, with the path, Copy and an Open that shows its folder (POST /api/settings/log/reveal; the row is hidden in magpie web, which writes no file). magpie log prints where every log is (the app's, app.old.log, the service's, the tui's background serve.log); --path the app's alone, -n N its last lines, -f follows it across a rotation. Docs: reference.md, gui-shell.md, site start (FAQ "Where is magpie's log?" and the CLI table) and privacy (files on your computer), en/zh/ja. Run: At 227ce6074 on origin/mainfbb1b36d1: - mote: go test ./internal/applog ./internal/appdir ./internal/cli ok; -run TestCoreScriptBudget ./internal/gui ok; GOOS=windows go vet ./internal/... and GOOS=linux go vet -tags nogui ./internal/... ok; gofmt -l clean. GUI, chromium: about-log (5 languages x 1100/420, and no row without a log), about-website, i18n-keys: 24 of 25, the one red "a plugin's words are its own" ("Unmarked") is the same at origin/mainfbb1b36d1(#4524). - WSL (magpie-desktop), webkit: about-log and about-website 21 of 21. - Windows (win-run): applog, appdir, tui ok; cli ok but TestLibraryMCPHub's TempDir cleanup (#4140, mcp-npm, not this change). - WSL full go test -tags nogui -timeout 45m ./... at the previous base03f609e3f: every package ok but reds that fail the same at origin/main03f609e3falone: TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestNoCommandBypassesProc (#4491), internal/agent's install-detection tests (#4033, #3548), and TestCoreScriptBudget, which was this change (app.js 321 over): its comment is cut to one line and both budgets are raised by the remaining 124 bytes, with no room added. - Broken by hand: with startLog left out of runGUI, TestTheAppWritesItsLog is red ("app wrote no log: open .../Library/Logs/magpie/app.log: no such file or directory"); with proc.UserPath taken out of openApp, TestGatewayStartsGetUserPath is red ("runGUI doesn't call proc.UserPath"). The guard now follows a start into a function or func var of this package, since the Wails start sits behind openApp for the test. - Real use on mote: the GUI build, magpie app in a sandbox HOME, wrote ~/Library/Logs/magpie/app.log (0600) with its "started" line; magpie log and magpie log -n 3 printed it. Not tried: the app opened from Windows Explorer or a Linux desktop launcher for real (the paths are unit-tested per OS, the writer on Windows and Linux); the full GUI suite (running on WSL after the push, reds filed if they fail at origin/main too).
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package appdir
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// Logs is where each system keeps an app's logs, and the data folder's
|
|
// logs portable: the app opened from the Finder wrote none (rayem1w on X).
|
|
func TestLogsOnEachSystem(t *testing.T) {
|
|
t.Setenv("APPIMAGE", "")
|
|
t.Cleanup(func() { UseExecutable("") })
|
|
UseExecutable("")
|
|
r := root(t)
|
|
home, err := Home()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(r, "local"))
|
|
t.Setenv("XDG_STATE_HOME", filepath.Join(r, "state"))
|
|
for goos, want := range map[string]string{
|
|
"darwin": filepath.Join(home, "Library", "Logs", "magpie"),
|
|
"windows": filepath.Join(r, "local", "magpie", "logs"),
|
|
"linux": filepath.Join(r, "state", "magpie"),
|
|
"freebsd": filepath.Join(r, "state", "magpie"),
|
|
} {
|
|
if got := logsOn(goos); got != want {
|
|
t.Errorf("%s: logs in %q, want %q", goos, got, want)
|
|
}
|
|
}
|
|
|
|
// unset or relative, the system's default under the home
|
|
for _, v := range []string{"", "relative"} {
|
|
t.Setenv("LOCALAPPDATA", v)
|
|
t.Setenv("XDG_STATE_HOME", v)
|
|
if got, want := logsOn("windows"), filepath.Join(home, "AppData", "Local", "magpie", "logs"); got != want {
|
|
t.Errorf("windows, LOCALAPPDATA %q: logs in %q, want %q", v, got, want)
|
|
}
|
|
if got, want := logsOn("linux"), filepath.Join(home, ".local", "state", "magpie"); got != want {
|
|
t.Errorf("linux, XDG_STATE_HOME %q: logs in %q, want %q", v, got, want)
|
|
}
|
|
}
|
|
|
|
exe := touch(t, filepath.Join(r, "port", "magpie"))
|
|
data := filepath.Join(r, "port", "data")
|
|
mkdir(t, data)
|
|
UseExecutable(exe)
|
|
for _, goos := range []string{"darwin", "windows", "linux"} {
|
|
if got, want := logsOn(goos), filepath.Join(data, "logs"); got != want {
|
|
t.Errorf("portable on %s: logs in %q, want %q", goos, got, want)
|
|
}
|
|
}
|
|
}
|