Skip to content

Commit

Permalink
Fix nil interface value when logged (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer authored Jan 9, 2025
1 parent 4a54146 commit 4d03d08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
on: [ push, pull_request ]
on:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
name: Continuous Integration
jobs:
lint:
Expand All @@ -11,7 +20,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.1
go-version: 1.23.4

- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -44,7 +53,7 @@ jobs:
name: Test
strategy:
matrix:
go-version: [ 1.17.0, 1.21.0, 1.22.0 ]
go-version: [ 1.18.0, 1.22.0, 1.23.0 ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -107,7 +116,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.1
go-version: 1.23.4

- name: Cache
uses: actions/cache@v4
Expand Down
11 changes: 10 additions & 1 deletion 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,16 @@ func NewSimpleTextValue(customizer ...func(*SimpleTextValue)) *SimpleTextValue {

// FormatTextValue implements TextValue.FormatTextValue().
func (instance *SimpleTextValue) FormatTextValue(v interface{}, _ log.Provider) ([]byte, error) {
if vl, ok := v.(fields.Lazy); ok {
vv := reflect.ValueOf(v)
if vv.Kind() == reflect.Pointer && vv.IsNil() {
v = ""
} else 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 4d03d08

Please sign in to comment.