Let logger work without file access
This commit is contained in:
parent
8a571dbee8
commit
94952b5766
1 changed files with 3 additions and 4 deletions
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
)
|
||||
|
@ -13,11 +12,11 @@ var LogFile = "config/log.txt"
|
|||
func LogInit() {
|
||||
f, err := os.OpenFile(LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening log file: %v", err)
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, nil))) // Fallback to stdout
|
||||
slog.Error("error opening log file, logging to stdout", "path", LogFile, "error", err)
|
||||
return
|
||||
}
|
||||
// No defer f.Close() because that breaks the MultiWriter
|
||||
|
||||
w := io.MultiWriter(f, os.Stdout)
|
||||
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(w, nil)))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue