Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt FormatFunc return type to the expected logrus.Fields type #23

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions logrusr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const logrusDiffToInfo = 4

// FormatFunc is the function to format log values with for non primitive data.
// By default, this is empty and the data will be JSON marshaled.
type FormatFunc func(interface{}) string
type FormatFunc func(interface{}) interface{}

// Option is options to give when construction a logrusr logger.
type Option func(l *logrusr)
Expand Down Expand Up @@ -150,7 +150,7 @@ func (l *logrusr) WithName(name string) logr.LogSink {
}

// listToLogrusFields converts a list of arbitrary length to key/value paris.
func listToLogrusFields(formatter func(interface{}) string, keysAndValues ...interface{}) logrus.Fields {
func listToLogrusFields(formatter FormatFunc, keysAndValues ...interface{}) logrus.Fields {
f := make(logrus.Fields)

// Skip all fields if it's not an even length list.
Expand Down
4 changes: 2 additions & 2 deletions logrusr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestLogging(t *testing.T) {
description string
logrusLevel logrus.Level
logFunc func(log logr.Logger)
formatter func(interface{}) string
formatter FormatFunc
reportCaller bool
defaultName []string
assertions map[string]string
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestLogging(t *testing.T) {
logFunc: func(log logr.Logger) {
log.Info("hello, world", "list", []int{1, 2, 3})
},
formatter: func(val interface{}) string {
formatter: func(val interface{}) interface{} {
return fmt.Sprintf("%v", val)
},
assertions: map[string]string{
Expand Down