Set
Loggerfield ofbadger.Optionsobject tonil
pathDirDB := GetMyPathDirDB()
optionsDB := badger.DefaultOptions(pathDirDB)
if !IsModeDebug {
optionsDB.Logger = nil // <-- Here!!!
}
myDB, err := badger.Open(optionsDB)BadgerDB outputs an INFO log by default if the key doesn't exist.
func getValue(myKey []byte) ([]byte, error) {
var (
valCopy []byte
err error
)
err = myDB.View(func(txn *badger.Txn) error {
valCopy = []byte("")
// Get looks for key and returns corresponding Item.
// If key is not found, ErrKeyNotFound is returned.
// It will output INFO by default as well.
item, err := txn.Get(myKey)
if err != nil {
return err
}
err = item.Value(func(val []byte) error {
valCopy = append([]byte{}, val...)
return nil
})
return err
})
return valCopy, err
}The output will be something like below.
badger 2021/06/24 03:56:15 INFO: All 1 tables opened in 0s
badger 2021/06/24 03:56:15 INFO: Discard stats nextEmptySlot: 0
badger 2021/06/24 03:56:15 INFO: Set nextTxnTs to 1
badger 2021/06/24 03:56:15 INFO: Deleting empty file: /tmp/SampleDB/000001.vlog
badger 2021/06/24 03:56:15 INFO: Lifetime L0 stalled for: 0s
badger 2021/06/24 03:56:15 INFO:
Level 0 [ ]: NumTables: 01. Size: 351 B of 0 B. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 64 MiB
Level 1 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB
Level 2 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB
Level 3 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB
Level 4 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB
Level 5 [ ]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB
Level 6 [B]: NumTables: 00. Size: 0 B of 10 MiB. Score: 0.00->0.00 StaleData: 0 B Target FileSize: 2.0 MiB
Level Done