logging: Add ENVOY_TAGGED_LOG macro to enable tagged logging#27882
logging: Add ENVOY_TAGGED_LOG macro to enable tagged logging#27882mattklein123 merged 5 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: ohadvano <ohadvano@gmail.com>
|
/assign @mattklein123 |
|
Opening this to initial review just to make sure this is on track before completing the implementation. @mattklein123 I'll appreciate your review on this. For context, this is part 2 in the implementation of #25959. |
Signed-off-by: ohadvano <ohadvano@gmail.com>
|
I think in general we would not want to pay any map costs in the case where the logs are disabled. Can you make sure this can all be done inline inside the macro and only constructed after the level, etc. decisions are made? Thanks. /wait |
|
|
||
| #define ENVOY_TAGGED_LOG_TO_LOGGER(LOGGER, LEVEL, TAGS, FORMAT, ...) \ | ||
| do { \ | ||
| if (ENVOY_LOG_COMP_LEVEL(LOGGER, LEVEL)) { \ |
There was a problem hiding this comment.
@mattklein123 I added this check for the logger level before doing the serialization and proceeding with the costlier operations - are there more checks I have missed that should be added?
There was a problem hiding this comment.
In your example you construct the map outside of the macro. We would optimally like to construct the map inside the macro if possible. Can you try that out?
There was a problem hiding this comment.
To make sure I understand you correctly - do you mean to move the code of serializeLogTags to inside the macro?
There was a problem hiding this comment.
Or have you meant the usage exmple of
std::map<std::string, std::string> tags{{"key", "val"}, {"key2", "val2"}};
ENVOY_TAGGED_LOG(info, tags, "some_message {}", "val");
The idea was that this map could have been pre-created and saved in some class member to be reused in multiple ENVOY_TAGGED_LOG calls.
Can you demonstrate an alternative usage example so I could better understand please?
There was a problem hiding this comment.
What I mean is I could imagine doing something like:
ENVOY_TAGGED_LOG(info, {make tags here somehow}, "some_message {}", "val");
I just want to make sure that works correctly also.
There was a problem hiding this comment.
Best option I could find is wrapping the tags map in parentheses, for example:
ENVOY_TAGGED_LOG(info, (std::map<std::string, std::string>{{"key", "val"}}), "some_message {}", "val");
If you define some using for example using LogTagsMap = std::map<std::string, std::string> then it would look like ENVOY_TAGGED_LOG(info, (LogTagsMap{{"key", "val"}}), "some_message {}", "val");, which is a bit nicer.
It's a bit awkward, but it works.. wdyt?
There was a problem hiding this comment.
Added tests that demonstrate and validate the two ways to use the macro, the PR is ready for review
Signed-off-by: ohadvano <ohadvano@gmail.com>
Signed-off-by: ohadvano <ohadvano@gmail.com>
|
/retest |
…oxy#27882) Signed-off-by: ohadvano <ohadvano@gmail.com> Signed-off-by: asheryer <asheryer@amazon.com>
…oxy#27882) Signed-off-by: ohadvano <ohadvano@gmail.com> Signed-off-by: Ryan Eskin <ryan.eskin89@protonmail.com>
Commit Message: logging: Add ENVOY_TAGGED_LOG macro to enable tagged logging
Additional Description: Further description below
Risk Level: low (new macro)
Testing: Unit tests
Docs Changes: None
Release Notes: None
Platform Specific Features: None
Example usage:
Expected output message:
[Tags: "key":"val","key2":"val2"] some message valThe idea here is that after #27278 was introduced to enable flushing application logs in JSON format, if
json_formatis set, then the%jflag would extract the tags from the message flushed to the sink, so the[Tags: "key":"val","key2":"val2"]part will be removed from the message. Additionally, a new flag will be introduced that will append the tags to the JSON string, so eventually we will get the following JSON string (for example):{"Timestamp":"%t","Message":"%j","key":"val","key2":"val2"}