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) {
|
||||
b.WriteString(value)
|
||||
} else {
|
||||
escapedQuote := fmt.Sprintf("\\%s", f.QuoteCharacter)
|
||||
escapedValue := strings.Replace(value, f.QuoteCharacter, escapedQuote, -1)
|
||||
|
||||
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, escapedValue, f.QuoteCharacter)
|
||||
b.WriteString(f.quoteString(value))
|
||||
}
|
||||
case error:
|
||||
errmsg := value.Error()
|
||||
if !f.needsQuoting(errmsg) {
|
||||
b.WriteString(errmsg)
|
||||
} else {
|
||||
escapedQuote := fmt.Sprintf("\\%s", f.QuoteCharacter)
|
||||
escapedErrmsg := strings.Replace(errmsg, f.QuoteCharacter, escapedQuote, -1)
|
||||
|
||||
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, escapedErrmsg, f.QuoteCharacter)
|
||||
b.WriteString(f.quoteString(errmsg))
|
||||
}
|
||||
default:
|
||||
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