Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
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
11 changes: 9 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ func formatFields(fields map[string]interface{}) string {

var sorted []string

for _, k := range keys {
sorted = append(sorted, fmt.Sprintf("%s=%q", k, fields[k]))
for _, key := range keys {
v := fields[key]
value, ok := v.(string)

if !ok {
value = fmt.Sprint(v)
}

sorted = append(sorted, fmt.Sprintf("%s=%q", key, value))
}

return strings.Join(sorted, " ")
Expand Down
27 changes: 27 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,30 @@ func TestLoggerFire(t *testing.T) {
err = ccLog.Logger.Hooks.Fire(logrus.InfoLevel, entry)
assert.Error(t, err)
}

func TestLoggerFormatFields(t *testing.T) {
assert := assert.New(t)

fields := logrus.Fields{
"zzz-last-field": "The End.",
"int": 999,
"string": "foo bar",
"float": 3.14159,
"bool-true": true,
"aaa-first-field": "winner!",
"bool-false": false,
}

expected := ""
expected += "aaa-first-field=\"winner!\""
expected += " bool-false=\"false\""
expected += " bool-true=\"true\""
expected += " float=\"3.14159\""
expected += " int=\"999\""
expected += " string=\"foo bar\""
expected += " zzz-last-field=\"The End.\""

result := formatFields(fields)

assert.Equal(expected, result)
}