Skip to content

Commit

Permalink
specify logger for bbolt
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 12, 2024
1 parent 8b9e179 commit cfbf672
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/storage/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func newBackend(bcfg BackendConfig) *backend {
bopts.NoSync = bcfg.UnsafeNoFsync
bopts.NoGrowSync = bcfg.UnsafeNoFsync
bopts.Mlock = bcfg.Mlock
bopts.Logger = newBoltLoggerZap(bcfg)

db, err := bolt.Open(bcfg.Path, 0600, bopts)
if err != nil {
Expand Down Expand Up @@ -659,3 +660,20 @@ func (s *snapshot) Close() error {
<-s.donec
return s.Tx.Rollback()
}

func newBoltLoggerZap(bcfg BackendConfig) bolt.Logger {
lg := bcfg.Logger.Named("bbolt")
return &zapBoltLogger{lg.WithOptions(zap.AddCallerSkip(1)).Sugar()}
}

type zapBoltLogger struct {
*zap.SugaredLogger
}

func (zl *zapBoltLogger) Warning(args ...any) {
zl.SugaredLogger.Warn(args...)
}

func (zl *zapBoltLogger) Warningf(format string, args ...any) {
zl.SugaredLogger.Warnf(format, args...)
}

0 comments on commit cfbf672

Please sign in to comment.