Skip to content

Commit da1dcac

Browse files
authored
fix(logging): fix direct access to logger (#1980)
## Problem Because the logger provided in the Options can be nil, directly interacting with it can cause panics. ## Solution This change fixes this issue by using the various logging methods provided by Options that wrap the Logger field.
1 parent 4df8389 commit da1dcac

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

iterator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (item *Item) yieldItemValue() ([]byte, func(), error) {
168168
db := item.txn.db
169169
result, cb, err := db.vlog.Read(vp, item.slice)
170170
if err != nil {
171-
db.opt.Logger.Errorf("Unable to read: Key: %v, Version : %v, meta: %v, userMeta: %v"+
171+
db.opt.Errorf("Unable to read: Key: %v, Version : %v, meta: %v, userMeta: %v"+
172172
" Error: %v", key, item.version, item.meta, item.userMeta, err)
173173
var txn *Txn
174174
if db.opt.managedTxns {
@@ -191,7 +191,7 @@ func (item *Item) yieldItemValue() ([]byte, func(), error) {
191191
if item.meta&bitValuePointer > 0 {
192192
vp.Decode(item.vptr)
193193
}
194-
db.opt.Logger.Errorf("Key: %v, Version : %v, meta: %v, userMeta: %v valuePointer: %+v",
194+
db.opt.Errorf("Key: %v, Version : %v, meta: %v, userMeta: %v valuePointer: %+v",
195195
item.Key(), item.version, item.meta, item.userMeta, vp)
196196
}
197197
}

stream_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (sw *StreamWriter) Write(buf *z.Buffer) error {
243243
for streamId := range closedStreams {
244244
writer, ok := sw.writers[streamId]
245245
if !ok {
246-
sw.db.opt.Logger.Warningf("Trying to close stream: %d, but no sorted "+
246+
sw.db.opt.Warningf("Trying to close stream: %d, but no sorted "+
247247
"writer found for it", streamId)
248248
continue
249249
}

value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ func (vlog *valueLog) Read(vp valuePointer, _ *y.Slice) ([]byte, func(), error)
969969
}
970970
}
971971
if uint32(len(kv)) < h.klen+h.vlen {
972-
vlog.db.opt.Logger.Errorf("Invalid read: vp: %+v", vp)
972+
vlog.db.opt.Errorf("Invalid read: vp: %+v", vp)
973973
return nil, nil, errors.Errorf("Invalid read: Len: %d read at:[%d:%d]",
974974
len(kv), h.klen, h.klen+h.vlen)
975975
}

0 commit comments

Comments
 (0)