Merge pull request #430 from nileshpatra/fix-debug-log-and-dir
Fix debug dir on linux and disable logging by default
This commit is contained in:
commit
09a9279558
@ -24,6 +24,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -31,11 +32,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var writer io.Writer
|
var writer io.Writer
|
||||||
var RecoverPrettyPanic bool
|
var RecoverPrettyPanic bool = true
|
||||||
var DeadlockDetection bool
|
var DeadlockDetection bool
|
||||||
var WriteLogs bool
|
var WriteLogs bool
|
||||||
var OnRecover func()
|
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 filepath.Join(xdgStateHome, "gomuks")
|
||||||
|
}
|
||||||
|
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 {
|
func getUname() string {
|
||||||
currUser, err := user.Current()
|
currUser, err := user.Current()
|
||||||
|
5
main.go
5
main.go
@ -63,13 +63,10 @@ func main() {
|
|||||||
debug.LogDirectory = debugDir
|
debug.LogDirectory = debugDir
|
||||||
}
|
}
|
||||||
debugLevel := strings.ToLower(os.Getenv("DEBUG"))
|
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" {
|
if debugLevel == "1" || debugLevel == "t" || debugLevel == "true" {
|
||||||
debug.RecoverPrettyPanic = false
|
debug.RecoverPrettyPanic = false
|
||||||
debug.DeadlockDetection = true
|
debug.DeadlockDetection = true
|
||||||
|
debug.WriteLogs = true
|
||||||
}
|
}
|
||||||
debug.Initialize()
|
debug.Initialize()
|
||||||
defer debug.Recover()
|
defer debug.Recover()
|
||||||
|
Loading…
Reference in New Issue
Block a user