Skip to content

Commit

Permalink
Show fields when logging object.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Jun 21, 2024
1 parent 2d29da7 commit f8009bd
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 f8009bd

Please sign in to comment.