log: Add "%j" to print message as JSON escaped string#15226
log: Add "%j" to print message as JSON escaped string#15226mattklein123 merged 6 commits intoenvoyproxy:mainfrom dio:fix-15020
Conversation
This patch adds a new custom flag `%j` to the log pattern to printthe actual message to log, but as escaped JSON string. Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
zuercher
left a comment
There was a problem hiding this comment.
I think the implication is that UTF-8 encoded strings are passed through without modification. Should we make that explicit in the comments? Otherwise just some style nits.
| position += 2; | ||
| break; | ||
| default: | ||
| if (character >= 0x00 and character <= 0x1f) { |
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
|
Thanks, @zuercher for the review, I have updated the comment and code per your review comments. |
| // Calculate the extra space to build a JSON escaped string. | ||
| // @param input input string. | ||
| // @return uint64_t the number of extra characters required to to build a JSON escaped string. | ||
| static uint64_t extraSpace(absl::string_view input) { |
There was a problem hiding this comment.
How can we ensure that extraSpace and escapeString remain in sync? Seems to me that we have some risk for writes past the end of the string. Granted, it's somewhat likely that we'll catch it if tests are written for all escape sequences.
There was a problem hiding this comment.
@dio is there a way for us not to copy+paste from the JSON dep? It would be pretty scary if they fix a bug and we don't here. I'm hoping we can just do some minimal Bazel BUILD dep pointed at the relevant header file.
Fixes istio#31137 Depends on envoyproxy/envoy#15226 - we can backport IFF we backport that
Fixes #31137 Depends on envoyproxy/envoy#15226 - we can backport IFF we backport that
Commit Message: This patch adds a new custom flag
%jto the log pattern to print the actual message to log as JSON escaped string.Additional description: This produces JSON escaped string for the
msg.payloadpart only, not the whole logline. Further description of the use case: #13636.Risk Level: Low
Testing: Unit
Docs Changes: Updated
Release Notes: Added
Fixes #15020
Signed-off-by: Dhi Aurrahman dio@rockybars.com