mirror of https://github.com/sirupsen/logrus.git
share common calling path in printKeyValue
Signed-off-by: Derek Che <drc@yahoo-inc.com>
This commit is contained in:
parent
03377c6168
commit
a243bbaa0b
|
@ -107,18 +107,16 @@ func needsQuoting(text string) bool {
|
||||||
func printKeyValue(b *bytes.Buffer, key, value interface{}) {
|
func printKeyValue(b *bytes.Buffer, key, value interface{}) {
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
break
|
||||||
|
case error:
|
||||||
|
value = value.(error).Error()
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(b, "%v=%v ", key, value)
|
||||||
|
}
|
||||||
|
|
||||||
if needsQuoting(value.(string)) {
|
if needsQuoting(value.(string)) {
|
||||||
fmt.Fprintf(b, "%v=%s ", key, value)
|
fmt.Fprintf(b, "%v=%s ", key, value)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(b, "%v=%q ", key, value)
|
fmt.Fprintf(b, "%v=%q ", key, value)
|
||||||
}
|
}
|
||||||
case error:
|
|
||||||
if needsQuoting(value.(error).Error()) {
|
|
||||||
fmt.Fprintf(b, "%v=%s ", key, value)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(b, "%v=%q ", key, value)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(b, "%v=%v ", key, value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue