fix: handle not being able to create log file

This commit is contained in:
Carlos Alexandro Becker 2024-07-10 10:42:21 -03:00
parent b80e8312f2
commit a1a85636ea
No known key found for this signature in database

7
log.go
View file

@ -1,7 +1,6 @@
package main
import (
"errors"
"os"
"path/filepath"
@ -24,15 +23,13 @@ func setupLog() (func() error, error) {
return nil, err
}
if err := os.MkdirAll(filepath.Dir(logFile), 0o644); err != nil {
if errors.Is(err, os.ErrPermission) {
// log disabled
return nil, nil
}
return nil, err
}
f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
if err != nil {
return nil, err
// log disabled
return nil, nil
}
log.SetOutput(f)
log.SetLevel(log.DebugLevel)