mirror of https://github.com/sirupsen/logrus.git
parent
fb62dbe2f2
commit
007cacdd34
|
@ -34,6 +34,9 @@ type TextFormatter struct {
|
||||||
// Force disabling colors.
|
// Force disabling colors.
|
||||||
DisableColors bool
|
DisableColors bool
|
||||||
|
|
||||||
|
// Force quoting of all values
|
||||||
|
ForceQuote bool
|
||||||
|
|
||||||
// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
|
// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
|
||||||
EnvironmentOverrideColors bool
|
EnvironmentOverrideColors bool
|
||||||
|
|
||||||
|
@ -283,6 +286,9 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TextFormatter) needsQuoting(text string) bool {
|
func (f *TextFormatter) needsQuoting(text string) bool {
|
||||||
|
if f.ForceQuote {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if f.QuoteEmptyFields && len(text) == 0 {
|
if f.QuoteEmptyFields && len(text) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,12 @@ func TestQuoting(t *testing.T) {
|
||||||
checkQuoting(true, "")
|
checkQuoting(true, "")
|
||||||
checkQuoting(false, "abcd")
|
checkQuoting(false, "abcd")
|
||||||
checkQuoting(true, errors.New("invalid argument"))
|
checkQuoting(true, errors.New("invalid argument"))
|
||||||
|
|
||||||
|
// Test forcing quotes.
|
||||||
|
tf.ForceQuote = true
|
||||||
|
checkQuoting(true, "")
|
||||||
|
checkQuoting(true, "abcd")
|
||||||
|
checkQuoting(true, errors.New("invalid argument"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEscaping(t *testing.T) {
|
func TestEscaping(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue