Skip to content

Commit

Permalink
Fix nil interface value logged
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Jan 9, 2025
1 parent 4a54146 commit a3518d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions native/formatter/text_value_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package formatter
import (
"encoding/json"
"fmt"
"reflect"

log "github.com/echocat/slf4g"
"github.com/echocat/slf4g/fields"
Expand All @@ -28,8 +29,18 @@ func NewSimpleTextValue(customizer ...func(*SimpleTextValue)) *SimpleTextValue {

// FormatTextValue implements TextValue.FormatTextValue().
func (instance *SimpleTextValue) FormatTextValue(v interface{}, _ log.Provider) ([]byte, error) {
vv := reflect.ValueOf(v)
if vv.Kind() == reflect.Pointer && vv.IsNil() {
v = ""
}

if vl, ok := v.(fields.Lazy); ok {
v = vl.Get()

vv = reflect.ValueOf(v)
if vv.Kind() == reflect.Pointer && vv.IsNil() {
v = ""
}
}

switch vs := v.(type) {
Expand Down

0 comments on commit a3518d8

Please sign in to comment.