godash/internal/logger/logger.go

26 lines
385 B
Go
Raw Normal View History

2023-10-26 11:42:14 +02:00
package logger
import (
"log/slog"
"os"
"time"
"github.com/lmittmann/tint"
)
func NewLogger(logLevel string) *slog.Logger {
w := os.Stderr
lvl := new(slog.Level)
level := slog.LevelInfo
err := lvl.UnmarshalText([]byte(logLevel))
if err == nil {
level = *lvl
}
return slog.New(tint.NewHandler(w, &tint.Options{
Level: &level,
TimeFormat: time.Kitchen,
}))
}