Using slog instead of log #768
Unanswered
purpose-robot
asked this question in
Q&A
Replies: 1 comment
-
@purpose-robot type Slogger struct {
*slog.Logger // embed *slog.Logger
}
// Printf implements the Printf method for goose.Logger
func (sl *Slogger) Printf(format string, v ...interface{}) {
sl.Info(fmt.Sprintf(format, v...))
}
// Fatalf implements the Fatalf method for goose.Logger
func (sl *Slogger) Fatalf(format string, v ...interface{}) {
sl.Error(fmt.Sprintf(format, v...))
os.Exit(1) // Ensure the process exits on fatal errors
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
how can I use slog instead of log when using goose?
When trying to set the default logger to slog, I got the following error message:
cannot use logger (variable of type *slog.Logger) as goose.Logger value in argument to goose.SetLogger: *slog.Logger does not implement goose.Logger (missing method Fatalf)
I figured out that I have to implement the missing
Fatalf
function in slog by myself but since I am still a beginner, I am not quite sure how to do this.Can someone provide me with a working example or explain how I could achieve this?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions