ytdl-web/pkg/utils/badgerlogger.go

41 lines
823 B
Go
Raw Permalink Normal View History

package utils
import (
"fmt"
"github.com/dgraph-io/badger/v2"
"golang.org/x/exp/slog"
)
type SlogLogger struct {
logger *slog.Logger
}
// Debugf implements badger.Logger
func (l *SlogLogger) Debugf(f string, a ...interface{}) {
l.logger.Debug(fmt.Sprintf(f, a...))
}
// Errorf implements badger.Logger
func (l *SlogLogger) Errorf(f string, a ...interface{}) {
l.logger.Error(fmt.Sprintf(f, a...))
}
// Infof implements badger.Logger
func (l *SlogLogger) Infof(f string, a ...interface{}) {
l.logger.Info(fmt.Sprintf(f, a...))
}
// Warningf implements badger.Logger
func (l *SlogLogger) Warningf(f string, a ...interface{}) {
l.logger.Warn(fmt.Sprintf(f, a...))
}
var _ badger.Logger = (*SlogLogger)(nil)
func NewBadgerLogger(logger *slog.Logger) badger.Logger {
return &SlogLogger{
logger: logger,
}
}