diff --git a/cointop/debug.go b/cointop/debug.go index aab5dee..631168c 100644 --- a/cointop/debug.go +++ b/cointop/debug.go @@ -1,13 +1,22 @@ package cointop import ( + "fmt" "os" + "github.com/cointop-sh/cointop/pkg/pathutil" log "github.com/sirupsen/logrus" ) func (ct *Cointop) initlog() { filename := "/tmp/cointop.log" + debugFile := os.Getenv("DEBUG_FILE") + if debugFile != "" { + filename = pathutil.NormalizePath(debugFile) + if filename != debugFile && os.Getenv("DEBUG") != "" { + fmt.Printf("Writing debug log to %s\n", filename) + } + } f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { panic(err) diff --git a/docs/content/faq.md b/docs/content/faq.md index cc3c391..7a2aa64 100644 --- a/docs/content/faq.md +++ b/docs/content/faq.md @@ -504,3 +504,5 @@ draft: false ```bash DEBUG=1 DEBUG_HTTP=1 cointop ``` + + If you set environment variable `DEBUG_FILE` you can explicitly provide a logfile location, rather than `/tmp/cointop.log` \ No newline at end of file diff --git a/pkg/pathutil/pathutil.go b/pkg/pathutil/pathutil.go index 7606705..02c52e4 100644 --- a/pkg/pathutil/pathutil.go +++ b/pkg/pathutil/pathutil.go @@ -53,6 +53,7 @@ func NormalizePath(path string) string { userHome := UserPreferredHomeDir() userConfigHome := UserPreferredConfigDir() userCacheHome := UserPreferredCacheDir() + userTempDir := os.TempDir() // expand tilde if strings.HasPrefix(path, "~/") { @@ -62,6 +63,7 @@ func NormalizePath(path string) string { path = strings.Replace(path, ":HOME:", userHome, -1) path = strings.Replace(path, ":PREFERRED_CONFIG_HOME:", userConfigHome, -1) path = strings.Replace(path, ":PREFERRED_CACHE_HOME:", userCacheHome, -1) + path = strings.Replace(path, ":PREFERRED_TEMP_DIR:", userTempDir, -1) path = strings.Replace(path, "/", string(filepath.Separator), -1) return filepath.Clean(path)