dumb/utils/logger.go

33 lines
519 B
Go
Raw Normal View History

2024-05-02 21:29:50 +01:00
package utils
import (
"fmt"
"io"
"log/slog"
2024-05-03 14:47:57 +01:00
"os"
2024-05-02 21:29:50 +01:00
)
type Logger struct {
slog *slog.Logger
}
func NewLogger(w io.WriteCloser) *Logger {
handler := slog.NewTextHandler(w, &slog.HandlerOptions{})
sl := slog.New(handler)
return &Logger{slog: sl}
}
func (l *Logger) Error(f string, args ...any) {
l.slog.Error(fmt.Sprintf(f, args...))
}
func (l *Logger) Info(f string, args ...any) {
l.slog.Info(fmt.Sprintf(f, args...))
}
2024-05-03 14:47:57 +01:00
func (l *Logger) Fatal(f string, args ...any) {
l.Error(f, args...)
os.Exit(1)
}