-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logger: implement Fancy Logger with fine-grained log control #11822
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very exciting - all us googlers miss having vlogs :-)
I think as long as benchmarks show that with fancy-mode off the performance changes are negligible we can do this inline. Meanwhile I'd encourage you to check out your CI results (doing a master merge might fix - we were having CI problems last week) @penguingao would you be up for first pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flushing out some readability comments first. I'll read the code more carefully later.
source/common/common/logger.h
Outdated
|
||
extern FancyMapPtr getFancyLogMap(); | ||
|
||
extern void setFancyLogger(std::string key, spdlog::level::level_enum log_level); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need extern for these functions?
If you simply want to declare and use them in the macros, would it make sense to create a fancy_logger.h and group these just there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I don't. Addressed now.
Signed-off-by: Jinhui Song <jinhuisong@google.com>
e0ed7f8
to
d618b96
Compare
Signed-off-by: Jinhui Song <jinhuisong@google.com>
/retest |
🤷♀️ nothing to rebuild. |
Registry::getSink()->setLock(lock_); | ||
Registry::getSink()->set_should_escape(should_escape_); | ||
Registry::setLogLevel(log_level_); | ||
Registry::setLogFormat(log_format_); | ||
|
||
if (mode == LoggerMode::Fancy) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is the right place to set your default log level. class Context is used to override logging behavior when it is created and restore the previous behavior when it is destructed.
But getFancyDefaultLevel is only used once for each log key (file name), meaning the Context class does not affect fancy log's behavior once fancy log is initialized.
I think the better way is to provide a pair of function in FancyContext that iterates through the loggers and change their log level and format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is added in FancyContext to enable later update of default level/format of different Context, and it's called in activate() now. But I think it's still necessary to set the default level in Context() as the map isn't complete when the 1st Context is initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make fancy_default_level_ and fancy_log_format_ non-static member? You can access them via the current_context_ global var. I think this makes it clearer about the life span of the fancy_default_level_ and fancy_log_format_.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems making them non-static needs another variable to represent the previous default level. Currently I set default before setting fancy_default_level so that I can compare new level with the old one.
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
/retest |
🤷♀️ nothing to rebuild. |
Signed-off-by: Jinhui Song <jinhuisong@google.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! modulo some more nits.
source/common/common/fancy_logger.h
Outdated
spdlog::logger* local_flogger = flogger.load(std::memory_order_relaxed); \ | ||
if (!local_flogger) { \ | ||
FancyContext::initFancyLogger(FANCY_KEY, flogger); \ | ||
flogger.load(std::memory_order_relaxed) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If you want to avoid the duplicated log(spdlog::source_loc{}...) call, you can do local_flogger = flogger.load() here. Remove the else condition. So:
if (!local_flogger) {
FancyContext::initFancyLogger(FANCY_KEY, flogger);
local_flogger = flogger.load(std::memory_order_relaxed);
}
local_flogger.log(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed. I didn't thought of that
return false; | ||
} | ||
|
||
void FancyContext::setDefaultFancyLevelFormat(spdlog::level::level_enum level, std::string format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to compare the previous default level vs the new default level. So that you can avoid the for loop if nothing changes.
Also, you can compare the logger's log level vs default log level so that you can avoid overriding the log level set to non default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. About the later comment: if fancy_default_level & fancy_log_format are made non-static, it seems I need another variable for previous default level & format. So I keep them static for now...
Registry::getSink()->setLock(lock_); | ||
Registry::getSink()->set_should_escape(should_escape_); | ||
Registry::setLogLevel(log_level_); | ||
Registry::setLogFormat(log_format_); | ||
|
||
if (mode == LoggerMode::Fancy) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make fancy_default_level_ and fancy_log_format_ non-static member? You can access them via the current_context_ global var. I think this makes it clearer about the life span of the fancy_default_level_ and fancy_log_format_.
Signed-off-by: Jinhui Song <jinhuisong@google.com>
5a30d45
to
2c33098
Compare
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
source/common/common/BUILD
Outdated
@@ -137,8 +137,14 @@ envoy_cc_library( | |||
# Contains minimal code for logging to stderr. | |||
envoy_cc_library( | |||
name = "minimal_logger_lib", | |||
srcs = ["logger.cc"], | |||
hdrs = ["logger.h"], | |||
srcs = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split this to a separate target? this is no longer minimal with fancy logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next PR I plan to hook ENVOY_LOG with FANCY_LOG (with option provided to developers), and logically I think Fancy logger will be part of the logger as we need to include fancy_logger.h in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still, in the next PR you can just change their names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you mean using another name like "fancy_logger_lib" for readability and keep current lib structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lizan Could you please give some clarification on which names you want me to change (or the lib structure)? Because the change of "minimal_logger_lib" seems unnecessary and very dirty. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks this is now looks better.
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
source/common/common/BUILD
Outdated
@@ -137,8 +137,14 @@ envoy_cc_library( | |||
# Contains minimal code for logging to stderr. | |||
envoy_cc_library( | |||
name = "minimal_logger_lib", | |||
srcs = ["logger.cc"], | |||
hdrs = ["logger.h"], | |||
srcs = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still, in the next PR you can just change their names?
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
Signed-off-by: Jinhui Song <jinhuisong@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last set of nit, otherwise LGTM
test/common/common/BUILD
Outdated
@@ -105,7 +105,9 @@ envoy_cc_test( | |||
envoy_cc_test( | |||
name = "log_macros_test", | |||
srcs = ["log_macros_test.cc"], | |||
external_deps = ["benchmark"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted now.
test/common/common/BUILD
Outdated
@@ -114,6 +116,21 @@ envoy_cc_test( | |||
], | |||
) | |||
|
|||
envoy_cc_benchmark_binary( | |||
name = "logger_perf_test", | |||
srcs = ["logger_perf_test.cc"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We name this *_speed_test for rest benchmarks, can you rename this one too? same for below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
FANCY_LOG(info, "Slow path test begins."); | ||
std::atomic<spdlog::logger*> logger; | ||
for (auto _ : state) { | ||
(void)_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(void)_; | |
UNREFERENCED_PARAMETER(_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
…ance test. Signed-off-by: Jinhui Song <jinhuisong@google.com>
@lizan Could you please help merge my branch as all checks have passed? Thanks! |
…oxy#11822) Implement a new logger called Fancy Logger with fine-grained control, e.g. file, function and line level. Additional Description: Some new macros are defined for basic usage but not hooked with any existing log macros. API for the logger is still in progress. Risk Level: Low Testing: unit test & benchmark Docs Changes: None Release Notes: None Signed-off-by: Jinhui Song <jinhuisong@google.com>
…oxy#11822) Implement a new logger called Fancy Logger with fine-grained control, e.g. file, function and line level. Additional Description: Some new macros are defined for basic usage but not hooked with any existing log macros. API for the logger is still in progress. Risk Level: Low Testing: unit test & benchmark Docs Changes: None Release Notes: None Signed-off-by: Jinhui Song <jinhuisong@google.com> Signed-off-by: chaoqinli <chaoqinli@google.com>
Commit Message: Implement a new logger called Fancy Logger with fine-grained control, e.g. file, function and line level.
Additional Description: Some new macros are defined for basic usage but not hooked with any existing log macros. API for the logger is still in progress.
Risk Level: Low
Testing: unit test & benchmark
Docs Changes: None
Release Notes: None