node-logfmt icon indicating copy to clipboard operation
node-logfmt copied to clipboard

Escape new lines

Open chdsbd opened this issue 7 years ago • 1 comments

I'm not sure, but I think it might be a good idea to escape new line characters. This way new lines in messages don't break the output formatting in console.

This would be similar to how JSON.stringify handles new lines.

// Current behavior
logfmt.stringify({'key':'hello\nworld'}) == "key=hello\nworld"
// New behavior
logfmt.stringify({'key':'hello\nworld'}) == "key=hello\\nworld"

chdsbd avatar Jan 06 '19 03:01 chdsbd

I haven't written up a post in https://github.com/kr/logfmt/issues/9 explaining why it is absolutely necessary to escape newlines.
TL;DR: Unescaped newlines introduce parsing ambiguities.

andsens avatar Jul 30 '21 08:07 andsens