fix: escaping of : and \ in keyvalue formatter

This commit is contained in:
Martin Riedl 2024-01-04 15:15:35 +01:00
parent a98708a4a9
commit ff82c54533
Signed by: martinr92
GPG key ID: FB68DA65516A804C
2 changed files with 2 additions and 2 deletions

View file

@ -65,7 +65,7 @@ func (formatter *FormatterKeyValue) addKV(key string, value any) {
val := fmt.Sprintf("%v", value) val := fmt.Sprintf("%v", value)
// check, if value should be escaped // check, if value should be escaped
if strings.ContainsAny(val, " \t\n\r=") { if strings.ContainsAny(val, " \t\n\r=:\\") {
val = fmt.Sprintf("%q", val) val = fmt.Sprintf("%q", val)
} }

View file

@ -26,7 +26,7 @@ func TestFormatterKeyValue(t *testing.T) {
}, },
Level: LevelInfo, Level: LevelInfo,
} }
result := `time=0001-01-01T00:00:00Z level=INFO message="Some Text" k1=v1 k2=v2` result := `time="0001-01-01T00:00:00Z" level=INFO message="Some Text" k1=v1 k2=v2`
// execute formatter // execute formatter
formatter := NewFormatterKeyValue() formatter := NewFormatterKeyValue()