diff --git a/relp_handler.go b/relp_handler.go index 3c98bae..01837de 100644 --- a/relp_handler.go +++ b/relp_handler.go @@ -10,6 +10,7 @@ import ( "net" "net/url" "os" + "os" "path/filepath" "strconv" "time" @@ -34,7 +35,7 @@ func getEnvAsDuration(name string, defaultVal time.Duration) time.Duration { } var ( - cacheDir = os.Getenv("LOGGER_CACHE_DIR") + cacheDir, _ = os.UserCacheDir() diskBufferLimit = getEnvAsInt("LOGGER_DISK_BUFFER_LIMIT", 100) diskWriteInterval = getEnvAsDuration("LOGGER_DISK_WRITE_INTERVAL", time.Second) relpDebug = os.Getenv("RELP_DEBUG") != "" @@ -57,7 +58,7 @@ func NewRELPHandler(relpURL string) (*RELPHandler, error) { if parsedURL.Scheme != "tcp" { return nil, fmt.Errorf("RELP URL must have the tcp scheme, got %s", parsedURL.Scheme) } - if err := os.MkdirAll(cacheDir, 0755); err != nil { + if err := os.MkdirAll(filepath.Join(cacheDir, "simplelog"), 0755); err != nil { return nil, fmt.Errorf("Failed to create cache directory: %v", err) } r := &RELPHandler{ @@ -257,7 +258,7 @@ func (r *RELPHandler) Shutdown() error { } func (r *RELPHandler) writeFailedToDisk(event Event) { - fileName := filepath.Join(cacheDir, uuid.New().String()+".logevent") + fileName := filepath.Join(cacheDir, "simplelog", uuid.New().String()+".logevent") data, _ := json.Marshal(event) ioutil.WriteFile(fileName, data, 0600) }