pcmt/slogging/log.go
leo 63e5a86cdc
All checks were successful
continuous-integration/drone/push Build is passing
slogging: clean up deadcode
2023-04-19 03:49:45 +02:00

43 lines
683 B
Go

package slogging
import (
"fmt"
"os"
"golang.org/x/exp/slog"
)
type Logger struct {
*slog.Logger
}
var logger *Logger
func GetLogger() *Logger {
return logger
}
func Init(jsonHandler bool) error {
if jsonHandler {
logger = &Logger{slog.New(slog.NewJSONHandler(os.Stderr))}
} else {
logger = &Logger{slog.New(slog.NewTextHandler(os.Stderr))}
}
logger.Info("slog logger initialised")
return nil
}
func (l *Logger) Infof(msg string, args ...any) {
l.Info(fmt.Sprintf(msg, args...))
}
func (l *Logger) Warnf(msg string, args ...any) {
l.Warn(fmt.Sprintf(msg, args...))
}
func (l *Logger) Errorf(msg string, args ...any) {
l.Error(fmt.Sprintf(msg, args...))
}