From 3c537986342dc704f7897cd4a11119ffbbf4f6b0 Mon Sep 17 00:00:00 2001 From: Nilesh Patra Date: Thu, 6 Jul 2023 18:25:33 +0000 Subject: [PATCH 1/3] Set debug log dir to ~/.local/state/gomuks on linux --- debug/debug.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/debug/debug.go b/debug/debug.go index 315d56e..4a0a1de 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -24,6 +24,7 @@ import ( "os" "os/user" "path/filepath" + "runtime" "runtime/debug" "time" @@ -35,7 +36,23 @@ var RecoverPrettyPanic bool var DeadlockDetection bool var WriteLogs bool var OnRecover func() -var LogDirectory = filepath.Join(os.TempDir(), "gomuks-"+getUname()) +var LogDirectory = GetUserDebugDir() + +func GetUserDebugDir() string { + if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + return filepath.Join(os.TempDir(), "gomuks-"+getUname()) + } + // See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html + if xdgStateHome := os.Getenv("XDG_STATE_HOME"); xdgStateHome != "" { + return xdgStateHome + } + home := os.Getenv("HOME") + if home == "" { + fmt.Println("XDG_STATE_HOME and HOME are both unset") + os.Exit(1) + } + return filepath.Join(home, ".local", "state", "gomuks") +} func getUname() string { currUser, err := user.Current() From 802d6afc551feb193d6bf2ced563756bc051bf2d Mon Sep 17 00:00:00 2001 From: Nilesh Patra Date: Thu, 6 Jul 2023 18:26:08 +0000 Subject: [PATCH 2/3] Disable logging by default, start logging onlu if DEBUG is set to 1 --- debug/debug.go | 2 +- main.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/debug/debug.go b/debug/debug.go index 4a0a1de..e62b078 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -67,7 +67,7 @@ func getUname() string { func Initialize() { err := os.MkdirAll(LogDirectory, 0750) if err != nil { - RecoverPrettyPanic = false + RecoverPrettyPanic = true DeadlockDetection = false WriteLogs = false return diff --git a/main.go b/main.go index 3083683..58401b5 100644 --- a/main.go +++ b/main.go @@ -63,13 +63,10 @@ func main() { debug.LogDirectory = debugDir } debugLevel := strings.ToLower(os.Getenv("DEBUG")) - if debugLevel != "0" && debugLevel != "f" && debugLevel != "false" { - debug.WriteLogs = true - debug.RecoverPrettyPanic = true - } if debugLevel == "1" || debugLevel == "t" || debugLevel == "true" { debug.RecoverPrettyPanic = false debug.DeadlockDetection = true + debug.WriteLogs = true } debug.Initialize() defer debug.Recover() From 2b36ee373794ae4d4df4de95ed9e1428b9157dc9 Mon Sep 17 00:00:00 2001 From: Nilesh Patra Date: Mon, 10 Jul 2023 01:31:18 +0530 Subject: [PATCH 3/3] fix xdg-update-dir and enable prettypanic by default --- debug/debug.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debug/debug.go b/debug/debug.go index e62b078..f350124 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -32,7 +32,7 @@ import ( ) var writer io.Writer -var RecoverPrettyPanic bool +var RecoverPrettyPanic bool = true var DeadlockDetection bool var WriteLogs bool var OnRecover func() @@ -44,7 +44,7 @@ func GetUserDebugDir() string { } // See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if xdgStateHome := os.Getenv("XDG_STATE_HOME"); xdgStateHome != "" { - return xdgStateHome + return filepath.Join(xdgStateHome, "gomuks") } home := os.Getenv("HOME") if home == "" { @@ -67,7 +67,7 @@ func getUname() string { func Initialize() { err := os.MkdirAll(LogDirectory, 0750) if err != nil { - RecoverPrettyPanic = true + RecoverPrettyPanic = false DeadlockDetection = false WriteLogs = false return