add bolt logger interface with slog for debugging (#22)

This commit is contained in:
T.v.Dein
2025-02-17 13:46:41 +01:00
committed by GitHub
parent 6d2800c72e
commit 44bb6a0a26
4 changed files with 43 additions and 11 deletions

View File

@@ -27,6 +27,8 @@ import (
"strings"
"time"
common "github.com/tlinden/anydb/common"
bolt "go.etcd.io/bbolt"
"google.golang.org/protobuf/proto"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
@@ -93,7 +95,14 @@ func (db *DB) Open() error {
}
}
b, err := bolt.Open(db.Dbfile, 0600, nil)
var opts *bolt.Options
if db.Debug {
log := common.Slogger{Logger: slog.Default()}
opts = &bolt.Options{Logger: log}
}
b, err := bolt.Open(db.Dbfile, 0600, opts)
if err != nil {
return fmt.Errorf("failed to open DB %s: %w", db.Dbfile, err)
}