Skip to content

Commit

Permalink
Merge pull request #3 from jortel/object-format
Browse files Browse the repository at this point in the history
Show fields when logging struct.
  • Loading branch information
jortel authored Jun 21, 2024
2 parents 2d29da7 + f8009bd commit 55d3b0b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions logr/log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package logr

import (
"testing"

liberr "github.com/jortel/go-utils/error"
)

func TestList(t *testing.T) {
log := WithName("Test")
type Persion struct {
Name string
Age int
}
p := Persion{
Name: "Elmer",
Age: 60,
}

err := liberr.New("Test")

log.Info("Test")
log.Info("Test", "person", p)
log.Error(err, "Test")
log.Error(err, "Test", "person", p)
}
3 changes: 2 additions & 1 deletion logr/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func fields(kvpair []any) log.Fields {
for i := range kvpair {
if i%2 != 0 {
key := fmt.Sprintf("%v", kvpair[i-1])
fields[key] = kvpair[i]
v := fmt.Sprintf("%+v", kvpair[i])
fields[key] = v
}
}
return fields
Expand Down

0 comments on commit 55d3b0b

Please sign in to comment.