logger: macros evaluate logging level before invoking logger#2676
logger: macros evaluate logging level before invoking logger#2676ggreenway merged 4 commits intoenvoyproxy:masterfrom
Conversation
…age severity. Code passed to logger as params will NOT be evaluated if message's severity is lower than logger's severity. Signed-off-by: Christoph Pakulski <paker8848@gmail.com>
ggreenway
left a comment
There was a problem hiding this comment.
This seems like a nice improvement.
The release build tests are failing with this.
| // log message with higher severity and make sure that params were evaluated. | ||
| GET_MISC_LOGGER().set_level(spdlog::level::info); | ||
| ENVOY_LOG_MISC(warn, "test message '{}'", i++); | ||
| ASSERT_THAT(i, testing::Eq(2)); |
| // params should not be evaluated. | ||
| GET_MISC_LOGGER().set_level(spdlog::level::critical); | ||
| ENVOY_LOG_MISC(error, "test message '{}'", i++); | ||
| ASSERT_THAT(i, testing::Eq(1)); |
| } | ||
|
|
||
| TEST(Logger, evaluateParams) { | ||
| auto i = 1; |
There was a problem hiding this comment.
Please give this a type: uint32_t i = 1;
There was a problem hiding this comment.
OK. Will change that to uint32_t. Thanks.
| } | ||
|
|
||
| TEST(Logger, doNotEvaluateParams) { | ||
| auto i = 1; |
mrice32
left a comment
There was a problem hiding this comment.
Great work! Thanks for adding this! Just one comment about the macro.
| * Convenience macro to log to a user-specified logger. | ||
| */ | ||
| #define ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, ...) ENVOY_LOG_##LEVEL##_TO_LOGGER(LOGGER, ##__VA_ARGS__) | ||
| #define ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, ...) \ |
There was a problem hiding this comment.
Would you mind adding a test for this? I think this may suffer from the not-a-statement macro issue (see here), but I'm not sure. Specifically, I'm worried about the case:
if (condition) ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, ...);
else f();
This may be the reason that the behavior at the callsite in source/common/http/filter/lua/lua_filter.cc needed to be updated.
There was a problem hiding this comment.
Wrapped macro into do ... while(0) based on the link you sent (thanks!).
I had to keep changes for source/common/http/filter/lua/lua_filter.cc.
spdlog::log ... returns void and statement
return ENVOY_LOG...
was an easy way to log and exit function in one step. It will not work with the new macro.
Added test to verify that the macro can be used inside if .. else ... Signed-off-by: Christoph Pakulski <paker8848@gmail.com>
|
I'd be happy to merge today but it looks like the tests are still failing? |
|
I am working on fixing the problem with CI tests. When ASSERT is used not in Envoy namespace compiler cannot find certain values. |
|
@cpakulski one other small request - would you mind editing your original description to match the pull request template? It's helpful for when we commit to have a standard format. thanks! https://github.com/envoyproxy/envoy/blob/master/PULL_REQUEST_TEMPLATE.md |
|
@alyssawilk How to run all CI tests on developer's machine? Just want to make sure that it all passes before PR. No problem - I will update description to match the template. |
|
I don't think there's a single command to run all of them but for any build you can do something like |
|
Description: logger's current severity level is checked before calling logger's API. This avoids evaluating parameters passed to the logger when message severity is lower than logger's setting. Before this change, params were evaluated even when the message was later on dropped by logger. |
…nvoy namespace. Signed-off-by: christoph <paker8848@gmail.com>
| #include "absl/strings/string_view.h" | ||
| #include "testing/base/public/benchmark.h" | ||
|
|
||
| using namespace Envoy; |
There was a problem hiding this comment.
Can this code be put into namespace Envoy, instead of adding a "using"?
There was a problem hiding this comment.
I see two options:
- move test code into Envoy namespace (most test code is already in that namespace - only few tests run in default ns)
- change MACRO to use FQ namespace Envoy::Logger::Logger instead of Logger::Logger.
I think that first option is a bit cleaner - will try to do that and will ask you to review it. Thanks.
There was a problem hiding this comment.
I'm fine with either of those solutions.
…:Logger. There are some benchmark tests which invoke logger from default namespace. Signed-off-by: Christoph Pakulski <paker8848@gmail.com>
|
This looks good, but somehow you've angered the DCO-bot. I think it's because your DCO-sign-off doesn't match the name in your git commit author. I've never seen that error before. |
|
@ggreenway Somehow I messed it up - do not know exactly how. I have fixed it in local repo and will push --force to overwrite the latest commit. Just waiting for other circleci tests to finish. |
|
@cpakulski this PR causes compilation failures when running with This used to not be a problem because the first use of the LOGGER argument in the macro (before this PR) is fenced appropriately: envoy/source/common/common/logger.h Lines 179 to 185 in 99d5fe9 I will leave it up to @lita (who is trying to get a deploy out at Lyft) if she wants to revert. And to coordinate with you @cpakulski |
|
Yea I am going to have to revert, as I am not able to quickly fix this myself. Feel free to submit another PR with the fix. Thanks! |
…nvoyproxy#2676)" This reverts commit 8078092.
|
Actually, rather than revert, I will merge lyft's envoy to the change before yours. If you can upstream the fix before Thursday, then there will be no need to revert. |
|
After further discussion with @ccaraman, we are going to revert this PR. |
…nvoyproxy#2676)" This reverts commit 8078092. Signed-off-by: Lita Cho <lcho@lyft.com>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org> Signed-off-by: JP Simard <jp@jpsim.com>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org> Signed-off-by: JP Simard <jp@jpsim.com>
Modified main logging macro to compare logger's severity with severity of the message to be logged. If message severity is lower, logger is not called and code passed as params is not evaluated.