mirror of https://github.com/sirupsen/logrus.git
Extract quoting into separate method
This commit is contained in:
parent
0383f49850
commit
0025402362
|
@ -174,22 +174,23 @@ func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
|
||||||
if !f.needsQuoting(value) {
|
if !f.needsQuoting(value) {
|
||||||
b.WriteString(value)
|
b.WriteString(value)
|
||||||
} else {
|
} else {
|
||||||
escapedQuote := fmt.Sprintf("\\%s", f.QuoteCharacter)
|
b.WriteString(f.quoteString(value))
|
||||||
escapedValue := strings.Replace(value, f.QuoteCharacter, escapedQuote, -1)
|
|
||||||
|
|
||||||
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, escapedValue, f.QuoteCharacter)
|
|
||||||
}
|
}
|
||||||
case error:
|
case error:
|
||||||
errmsg := value.Error()
|
errmsg := value.Error()
|
||||||
if !f.needsQuoting(errmsg) {
|
if !f.needsQuoting(errmsg) {
|
||||||
b.WriteString(errmsg)
|
b.WriteString(errmsg)
|
||||||
} else {
|
} else {
|
||||||
escapedQuote := fmt.Sprintf("\\%s", f.QuoteCharacter)
|
b.WriteString(f.quoteString(errmsg))
|
||||||
escapedErrmsg := strings.Replace(errmsg, f.QuoteCharacter, escapedQuote, -1)
|
|
||||||
|
|
||||||
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, escapedErrmsg, f.QuoteCharacter)
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Fprint(b, value)
|
fmt.Fprint(b, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *TextFormatter) quoteString(v string) string {
|
||||||
|
escapedQuote := fmt.Sprintf("\\%s", f.QuoteCharacter)
|
||||||
|
escapedValue := strings.Replace(v, f.QuoteCharacter, escapedQuote, -1)
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s%v%s", f.QuoteCharacter, escapedValue, f.QuoteCharacter)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue