diff --git a/internal/cmd/root.go b/internal/cmd/root.go index a8364ac4af3c32a21a36af35df9c40f4b278087c..b8e751b7ea47d40405974402a474037e69bf9ce4 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -416,6 +416,14 @@ func connectToServer(cmd *cobra.Command) (*client.Client, *proto.Workspace, func // version matches the client; on mismatch it shuts down the old server // and starts a fresh one. func ensureServer(cmd *cobra.Command, hostURL *url.URL) error { + // Initialize the persistent log here so stale-socket diagnostics + // emitted before connectToServer runs are captured in the per-host + // server log file. crushlog.Setup uses sync.Once internally, so the + // later call from connectToServer becomes a no-op. + debug, _ := cmd.Flags().GetBool("debug") + logFile := filepath.Join(config.GlobalCacheDir(), "server-"+safeHostName(hostURL), "crush.log") + crushlog.Setup(logFile, debug) + switch hostURL.Scheme { case "unix", "npipe": needsStart := false