Skip to content

Commit

Permalink
Merge pull request etcd-io#17237 from ahrtr/bbolt_logger_20240112
Browse files Browse the repository at this point in the history
Specify logger for bbolt
  • Loading branch information
ahrtr authored Jan 13, 2024
2 parents 10bf636 + cfbf672 commit 9ded10e
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 9ded10e

Please sign in to comment.