make sure no leading or trailing spaces
This changed printColored and printKeyValue to print in same way with prefix space instead of trailing space, to make it easier to slice out when returning in Format; The test cases are to make sure msg formartting doesn't include leading or trailing spaces; Closes #99 Signed-off-by: Derek Che <drc@yahoo-inc.com>
This commit is contained in:
+5
-5
@@ -69,7 +69,7 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
||||
}
|
||||
|
||||
b.WriteByte('\n')
|
||||
return b.Bytes(), nil
|
||||
return b.Bytes()[1:], nil
|
||||
}
|
||||
|
||||
func printColored(b *bytes.Buffer, entry *Entry, keys []string) {
|
||||
@@ -85,7 +85,7 @@ func printColored(b *bytes.Buffer, entry *Entry, keys []string) {
|
||||
|
||||
levelText := strings.ToUpper(entry.Level.String())[0:4]
|
||||
|
||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message)
|
||||
fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m[%04d] %-44s", levelColor, levelText, miniTS(), entry.Message)
|
||||
for _, k := range keys {
|
||||
v := entry.Data[k]
|
||||
fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=%v", levelColor, k, v)
|
||||
@@ -111,12 +111,12 @@ func printKeyValue(b *bytes.Buffer, key, value interface{}) {
|
||||
case error:
|
||||
value = value.(error).Error()
|
||||
default:
|
||||
fmt.Fprintf(b, "%v=%v ", key, value)
|
||||
fmt.Fprintf(b, " %v=%v", key, value)
|
||||
}
|
||||
|
||||
if needsQuoting(value.(string)) {
|
||||
fmt.Fprintf(b, "%v=%s ", key, value)
|
||||
fmt.Fprintf(b, " %v=%s", key, value)
|
||||
} else {
|
||||
fmt.Fprintf(b, "%v=%q ", key, value)
|
||||
fmt.Fprintf(b, " %v=%q", key, value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user