Merge pull request #68 from Sirupsen/errors-should-be-in-string

textformatter: errors should be in quotes like strings are
This commit is contained in:
Simon Eskildsen 2014-10-03 12:39:12 -04:00
commit 965349de21
1 changed files with 8 additions and 7 deletions

View File

@ -53,11 +53,11 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
if isColored { if isColored {
printColored(b, entry, keys) printColored(b, entry, keys)
} else { } else {
f.AppendKeyValue(b, "time", entry.Time.Format(time.RFC3339)) f.appendKeyValue(b, "time", entry.Time.Format(time.RFC3339))
f.AppendKeyValue(b, "level", entry.Level.String()) f.appendKeyValue(b, "level", entry.Level.String())
f.AppendKeyValue(b, "msg", entry.Message) f.appendKeyValue(b, "msg", entry.Message)
for _, key := range keys { for _, key := range keys {
f.AppendKeyValue(b, key, entry.Data[key]) f.appendKeyValue(b, key, entry.Data[key])
} }
} }
@ -85,10 +85,11 @@ func printColored(b *bytes.Buffer, entry *Entry, keys []string) {
} }
} }
func (f *TextFormatter) AppendKeyValue(b *bytes.Buffer, key, value interface{}) { func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key, value interface{}) {
if _, ok := value.(string); ok { switch value.(type) {
case string, error:
fmt.Fprintf(b, "%v=%q ", key, value) fmt.Fprintf(b, "%v=%q ", key, value)
} else { default:
fmt.Fprintf(b, "%v=%v ", key, value) fmt.Fprintf(b, "%v=%v ", key, value)
} }
} }