Isn't `slog.Fatal()` meant to call `os.Exit(1)`?
yermulnik opened this issue · comments
I'm expecting slog.Fatal
to call os.Exit(1)
to reflect log.Fatal()
, but this is not happening.
Is this expected or am I doing something incorrect?
package main
import (
"github.com/gookit/slog"
)
func main() {
slog.Info("info log message")
slog.Fatal("fatal log message")
slog.Info("info log message")
}
> go run ./main.go ; echo $?
[2024/04/05T19:13:52.904] [application] [INFO] [main.go:8,main] info log message
[2024/04/05T19:13:52.904] [application] [FATAL] [main.go:9,main] fatal log message
[2024/04/05T19:13:52.904] [application] [INFO] [main.go:10,main] info log message
0
https://github.com/gookit/slog/blob/master/common.go#L56-L58
// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
// logging level <= FatalLevel.
FatalLevel Level = 200
I'd expect Panic to panic()
, Fatal to os.Exit(1)
, and everything else to just print.
Am I misinterpreting the idea and the code?
hi @yermulnik logger.ExitFunc
is not set by default, so Fatal will not exit.
You can set it:
// for std logger
slog.SetExitFunc(os.Exit)
// for new logger
l := slog.New(func(l *slog.Logger) {
l.ExitFunc = os.Exit
})
@inhere Thanks for the pointer 👍🏻