Skip to content

Commit

Permalink
moves logger to y
Browse files Browse the repository at this point in the history
  • Loading branch information
gabru-md committed Jan 27, 2020
1 parent 7b98dce commit 0b81618
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
40 changes: 37 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/dgraph-io/badger/v2/options"
"github.com/dgraph-io/badger/v2/table"
"github.com/dgraph-io/badger/v2/y"
)

// Note: If you add a new option X make sure you also add a WithX method on Options.
Expand All @@ -46,7 +47,7 @@ type Options struct {
NumVersionsToKeep int
ReadOnly bool
Truncate bool
Logger Logger
Logger y.Logger
Compression options.CompressionType
InMemory bool

Expand Down Expand Up @@ -144,7 +145,7 @@ func DefaultOptions(path string) Options {
ValueLogMaxEntries: 1000000,
ValueThreshold: 32,
Truncate: false,
Logger: defaultLogger,
Logger: y.DefaultLogger(),
LogRotatesToFlush: 2,
EncryptionKey: []byte{},
EncryptionKeyRotationDuration: 10 * 24 * time.Hour, // Default 10 days.
Expand Down Expand Up @@ -276,7 +277,7 @@ func (opt Options) WithTruncate(val bool) Options {
// Logger provides a way to configure what logger each value of badger.DB uses.
//
// The default value of Logger writes to stderr using the log package from the Go standard library.
func (opt Options) WithLogger(val Logger) Options {
func (opt Options) WithLogger(val y.Logger) Options {
opt.Logger = val
return opt
}
Expand Down Expand Up @@ -562,3 +563,36 @@ func (opt Options) WithZSTDCompressionLevel(cLevel int) Options {
opt.ZSTDCompressionLevel = cLevel
return opt
}

// Errorf logs an ERROR log message to the logger specified in opts or to the
// global logger if no logger is specified in opts.
func (opt *Options) Errorf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Errorf(format, v...)
}

// Infof logs an INFO message to the logger specified in opts.
func (opt *Options) Infof(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Infof(format, v...)
}

// Warningf logs a WARNING message to the logger specified in opts.
func (opt *Options) Warningf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Warningf(format, v...)
}

// Debugf logs a DEBUG message to the logger specified in opts.
func (opt *Options) Debugf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Debugf(format, v...)
}
4 changes: 2 additions & 2 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func newOracle(opt Options) *oracle {
txnMark: &y.WaterMark{Name: "badger.TxnTimestamp"},
closer: y.NewCloser(2),
}
orc.readMark.Init(orc.closer, opt)
orc.txnMark.Init(orc.closer, opt)
orc.readMark.Init(orc.closer, opt.Logger)
orc.txnMark.Init(orc.closer, opt.Logger)
return orc
}

Expand Down
35 changes: 1 addition & 34 deletions logger.go → y/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package badger
package y

import (
"log"
Expand All @@ -29,39 +29,6 @@ type Logger interface {
Debugf(string, ...interface{})
}

// Errorf logs an ERROR log message to the logger specified in opts or to the
// global logger if no logger is specified in opts.
func (opt *Options) Errorf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Errorf(format, v...)
}

// Infof logs an INFO message to the logger specified in opts.
func (opt *Options) Infof(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Infof(format, v...)
}

// Warningf logs a WARNING message to the logger specified in opts.
func (opt *Options) Warningf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Warningf(format, v...)
}

// Debugf logs a DEBUG message to the logger specified in opts.
func (opt *Options) Debugf(format string, v ...interface{}) {
if opt.Logger == nil {
return
}
opt.Logger.Debugf(format, v...)
}

type defaultLog struct {
*log.Logger
}
Expand Down
2 changes: 1 addition & 1 deletion logger_test.go → y/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package badger
package y

import (
"fmt"
Expand Down
8 changes: 3 additions & 5 deletions y/watermark.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"container/heap"
"context"
"sync/atomic"

badger "github.com/dgraph-io/badger/v2"
)

type uint64Heap []uint64
Expand Down Expand Up @@ -64,13 +62,13 @@ type WaterMark struct {
lastIndex uint64
Name string
markCh chan mark
logger badger.Logger
logger Logger
}

// Init initializes a WaterMark struct. MUST be called before using it.
func (w *WaterMark) Init(closer *Closer, opt badger.Options) {
func (w *WaterMark) Init(closer *Closer, logger Logger) {
w.markCh = make(chan mark, 100)
w.logger = opt.Logger
w.logger = logger
go w.process(closer)
}

Expand Down

0 comments on commit 0b81618

Please sign in to comment.