-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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: Make log prefix configurable #10693
logger: Make log prefix configurable #10693
Conversation
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
I haven't looked at the code, but quick drive-by suggestion based on the description. The worst offender is |
This change's only goal is to remove file/line number from the compile-time prefixing to runtime format option. Fancy stripping can be done as a follow up. |
/lgtm api |
@dio Can you check if it is a right direction in terms of backward compatibility, please? |
@ggreenway @jmarantz can you also take a quick high level look at this and see if you like the direction? |
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.
It looks like spdlog has support for explicit format strings for source file, etc as %@, %#, %s, %g (https://github.com/gabime/spdlog/wiki/3.-Custom-formatting).
I'd like to see those used to get the full flexibility of the formatting. I'd be ok with changing the default format string to [%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v
which would be the equivalent of what we have now, plumbing through whatever spdlog needs to make that work properly, and telling people with a custom log format that they'll need to update if they want to keep source file references in their logs.
Does anyone have a sense of how many people actually override the default log format?
api/envoy/admin/v3/server_info.proto
Outdated
@@ -115,6 +115,9 @@ message CommandLineOptions { | |||
// See :option:`--log-format-escaped` for details. | |||
bool log_format_escaped = 27; | |||
|
|||
// See :option:`--log-format-prefix-with-location` for details. | |||
bool log_format_prefix_with_location = 29; |
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.
Should this be inverted, so that the default unset value of false keeps the same behavior?
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.
This is a temporary flag, I plan to invert the default in 1 release from now and delete in 2 releases from now (following the breaking change policy).
source/common/common/logger.cc
Outdated
const spdlog::details::log_msg* msg = &msg_candidate; | ||
// This memory buffer is used for compatibility and has to be in the scope of the function to | ||
// avoid use-after-free. | ||
// TODO(euroelessar): Delete this logic after after 0.16 release. |
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.
0.16 release of what? spdlog? Envoy 1.16? Also, what is expected to change at that time which makes it ok to delete this?
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.
Two envoy releases from now, based on the breaking change policy). This logic can be deleted if it is acceptable to not preserve old behavior (and not provide an ability to revert to old behavior).
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'd like to see those used to get the full flexibility of the formatting. I'd be ok with changing the default format string to [%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v which would be the equivalent of what we have now, plumbing through whatever spdlog needs to make that work properly, and telling people with a custom log format that they'll need to update if they want to keep source file references in their logs.
This PR plumbs all the necessary information to spdlog to be able to use %g
, %#
, and friends. The concern is mostly around two points:
- Users can override the format string
- Users can pass
--log-format-escaped
Combination of this two points assumes that users may have an automation which consumes envoy logs, so changing the format is a breaking change for them. The change is that file location is not part of %v
anymore.
All the --log-format-prefix-with-location
-related work in this PR is to provide some time for users to migrate to a new format.
source/common/common/logger.cc
Outdated
const spdlog::details::log_msg* msg = &msg_candidate; | ||
// This memory buffer is used for compatibility and has to be in the scope of the function to | ||
// avoid use-after-free. | ||
// TODO(euroelessar): Delete this logic after after 0.16 release. |
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.
Two envoy releases from now, based on the breaking change policy). This logic can be deleted if it is acceptable to not preserve old behavior (and not provide an ability to revert to old behavior).
Ok, I understand your plan now; that makes sense. However, if we add a field to the protobufs, I think that it can't be removed immediately when it no longer applies, only deprecated. So the temporary part of this PR will live for a very long time. But that's probably fine. As an alternate approach, we could consider a runtime override for this instead of config. Also, instead of writing code to generate the source prefix, what if you scan the format string, and replace |
@alyssawilk or @htuch can you comment on the best way to add the needed knob/config to migrate from the current behavior to the new behavior? |
We potentially can not include it into protobuf definition if it's transient, thoughts?
Isn't runtime a bit too late from initialization order point of view?
This doesn't work well with |
Can you post an example of how they'd be different. I looked at it and thought I determined they would be the same, but I'm probably missing something. |
Oh, you're right. For some reason I've thought it also wraps the message in quotes. This leaves us with two approaches:
What do you prefer? |
I'm in favor of adding a new CLI flag to handle this. This isn't a breaking xDS API consideration, since this is the CLI API, but I think we should treat this similar to runtime deprecations and provide advanced notice that this is going to happen. |
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Updated, please have another look and tell if this direction is better. |
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 like the direction this is going. This will be great.
…igurable Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
docs/root/operations/cli.rst
Outdated
.. option:: --log-format-prefix-with-location <1|0> | ||
|
||
*(optional)* This temporary flag allows replacing all entries of ``"%v"`` in the log format by | ||
``"[%g:%#] "``. This flag is provided for migration purposes only. If this is not set, a |
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.
replaces with [%g:%#] %v
(you forgot the %v)
source/server/options_impl.cc
Outdated
@@ -92,6 +93,10 @@ OptionsImpl::OptionsImpl(std::vector<std::string> args, | |||
TCLAP::SwitchArg log_format_escaped("", "log-format-escaped", | |||
"Escape c-style escape sequences in the application logs", | |||
cmd, false); | |||
TCLAP::ValueArg<bool> log_format_prefix_with_location( | |||
"", "log-format-prefix-with-location", | |||
"Prefix all entrancies of '%v' in log format with with '[%g:%#] ' ('[path/to/file.cc:99] ').", |
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 liked "occurrences" better than "entrancies"
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.
Looks good. Thanks!
Can you merge master? I'm not sure what stats integration test is failing. /wait |
…igurable Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Hmm. I don't understand it, but this seems to be changing the stats mem test numbers. cc @jmarantz (Also sorry but please merge maser again to fix coverage and OSX). /wait |
…igurable Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@mattklein123 Stats memory failure is gone after rebase. |
Sent a fix for the redis failure as a separate pr: #10840 |
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!
…igurable Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
cf502d7
|
…igurable Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.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.
Thanks!
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com> Signed-off-by: pengg <pengg@google.com>
Description: Move
[%g:%#]
message prefix from compile-time macros to log format.Please note that this change does not change behavior iff envoy is used with none logger formatting-related command line options.
Risk Level: medium (no-op but does increase cost of logging by default)
Testing: manual run of test & verifying output
Docs Changes: TODO
Release Notes: TODO
Fixes #10688