summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Roberts <lyricnz@users.noreply.github.com>2021-10-18 16:16:23 +1100
committerGitHub <noreply@github.com>2021-10-18 16:16:23 +1100
commit73a00588ba1c8c40fd5e54d860d47bb6222fe9d6 (patch)
tree96db0d7c6ba3c105bb19109d5156da7fc96ce555
parent57ca7d8dbaf5872faacc73f85ac3ba792a74c62f (diff)
If $DEBUG_FILE is set, use that rather than /tmp/cointop.log (#236)
-rw-r--r--cointop/debug.go9
-rw-r--r--docs/content/faq.md2
-rw-r--r--pkg/pathutil/pathutil.go2
3 files changed, 13 insertions, 0 deletions
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)