Make chi use slog
This commit is contained in:
parent
f556ae0460
commit
4d8cee17df
1 changed files with 5 additions and 0 deletions
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
@ -19,4 +21,7 @@ func LogInit() {
|
||||||
// No defer f.Close() because that breaks the MultiWriter
|
// No defer f.Close() because that breaks the MultiWriter
|
||||||
w := io.MultiWriter(f, os.Stdout)
|
w := io.MultiWriter(f, os.Stdout)
|
||||||
slog.SetDefault(slog.New(slog.NewTextHandler(w, nil)))
|
slog.SetDefault(slog.New(slog.NewTextHandler(w, nil)))
|
||||||
|
|
||||||
|
// Make chi log to file too
|
||||||
|
middleware.DefaultLogger = middleware.RequestLogger(&middleware.DefaultLogFormatter{Logger: log.Default(), NoColor: true})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue