Description
Quote backslashes to 1) resolve parsing issues with external tools 2) disambiguate quoting logic.
Why
External Tool Parsing
Grafana's logfmt parser doesn't accept e.g. foo="\". It simply discards the pair:
PASS
{...} | line_format "foo=\"\\\"" | logfmt
FAIL
{...} | line_format "foo=\"\\\\\"" | logfmt
Ambiguous Quoting
Several kinds of string are quoted to exactly the same value, making it impossible to undo the quoting. Specifically, looking at https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py#L44 , the following pairs of strings quote to the same values:
" and \" -> \"
- newline and
\n -> \n
This makes it impossible to recover the input strings. A simple change would solve this: require backslashes on input to also be quoted.
Description
Quote backslashes to 1) resolve parsing issues with external tools 2) disambiguate quoting logic.
Why
External Tool Parsing
Grafana's logfmt parser doesn't accept e.g.
foo="\". It simply discards the pair:PASS
FAIL
Ambiguous Quoting
Several kinds of string are quoted to exactly the same value, making it impossible to undo the quoting. Specifically, looking at https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py#L44 , the following pairs of strings quote to the same values:
"and\"->\"\n->\nThis makes it impossible to recover the input strings. A simple change would solve this: require backslashes on input to also be quoted.