Skip to content

Commit

Permalink
🚚 move badger specific logger interface to logging package
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdd committed Aug 24, 2024
1 parent dedb7ab commit 1cd4747
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
26 changes: 26 additions & 0 deletions internal/logging/badger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package logging

import (
"fmt"
"log/slog"
)

type BadgerLogger struct {
Channel string
}

func (l *BadgerLogger) Errorf(format string, v ...interface{}) {
slog.Error(fmt.Sprintf(format, v...), "channel", l.Channel)
}

func (l *BadgerLogger) Warningf(format string, v ...interface{}) {
slog.Warn(fmt.Sprintf(format, v...), "channel", l.Channel)
}

func (l *BadgerLogger) Infof(format string, v ...interface{}) {
slog.Info(fmt.Sprintf(format, v...), "channel", l.Channel)
}

func (l *BadgerLogger) Debugf(format string, v ...interface{}) {
slog.Debug(fmt.Sprintf(format, v...), "channel", l.Channel)
}
24 changes: 0 additions & 24 deletions internal/logstorage/logger.go

This file was deleted.

4 changes: 3 additions & 1 deletion internal/logstorage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/options"

"link-society.com/flowg/internal/logging"
)

type Storage struct {
Expand All @@ -22,7 +24,7 @@ type Storage struct {
func NewStorage(dbPath string) (*Storage, error) {
opts := badger.
DefaultOptions(dbPath).
WithLogger(&serverLogger{}).
WithLogger(&logging.BadgerLogger{Channel: "logstorage"}).
WithCompression(options.ZSTD)

db, err := badger.Open(opts)
Expand Down

0 comments on commit 1cd4747

Please sign in to comment.