-
Notifications
You must be signed in to change notification settings - Fork 37.4k
logging: Simplify API for level based logging #28318
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
This implements I figure the main benefit of categories is to be able to selectively turn logging on/off -- but for unconditional logging, you don't have that benefit, so might as well just drop the category entirely, and just have the message be descriptive enough directly. Note that this effectively reverts #25306. It should be compatible with other in-progress PRs -- it only deprecates the This seems like a straightforward way of getting the logging stuff finished up. cc @jonatack |
8d527cc
to
cc56df3
Compare
cc56df3
to
f732efb
Compare
sample scripted diff code:
|
Concept ACK |
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.
Approach ACK. Makes sense to keep heavily used code snippets short.
This should also fix the issue of Info/Warning/Error messages not having a clear category and forcing the dev to somehow come up with one (or explicitly having to pick None
)
Is this ready for review, or any reason why this is still in draft? |
I was hoping for early feedback from @jonatack and initially wasn't happy with the original "break the -loglevel command line, do stuff, then replace it" commit order (that's now fixed). But no reason it can't be reviewed now. It could also be split up to separate out the |
I'll have a look later today but my initial read, to be confirmed, was Approach NACK in the direction, which I'll detail more on, and that this would hinder progress more than help. I've been waiting for the merge of the bug fix, tests and updated docs in #27231 to continue on the next steps, as I thought it would be merged quickly (as bugfixes normally would be) and which is still waiting on re-ACKs after taking everyone's feedback. ISTM this conflicts with it, which doesn't help either. It doesn't make sense to conflict with that PR for this one IMO. |
Err, perhaps it was because I made some more changes and didn't push them? [EDIT: Oh, was just some additional lint things] |
f732efb
to
451f2e7
Compare
The first 6 commits apply cleanly on top of it; though |
Thanks, will review properly asap. |
Absent the behavior changes, assuming they are controversial, you could also just split out the naming stuff. I don't see the benefit of making the code overly verbose and typing I don't have an opinion on the category and I think anything is probably fine 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.
Some thoughts, commit-by-commit.
068de7a The idea behind the severity level logging is to ultimately have only one macro like Log(category, level)
with one consistent, simple interface for everyone -- both developers updating logging in the code and people who read the logs -- and remove all the other macros when we're ready, simplifying the logging macros, tests, and benchmarks. This commit not only would add several more macros, but also with different interfaces for developers to remember or look up, rather than just one.
94e1b46 This would move the category from the prefix back into the log message string on an ad hoc basis, would be less consistent, and IMO a step backward.
f20bfc3 Non-urgent approach ACK, I can pull it into the parent in #25203 if you like.
b3bf2fa This would be a step back, I think, away from consistent explicit logging, to requiring remembering more implicit mental context baggage ("why do I see categories for these logs and not for those?") Also, the prefix allows not needing to put the category manually into the log strings.
53a7f76 Much of the value from severity level logging will come from making some of the noisy categories (net
in particular, and maybe validation and mempool) much more useful by selecting which LogPrints become debug vs trace, and in general, by selecting which LogPrintfs become info, warning, or error.
4906f49 is an incomplete version of 118c756
(#25203) in the parent pull.
99ac8b1 As discussed in #27231 (comment), it seems to make sense to drop the NONE
category and level enums from logging.{h,cpp}
when we remove the deprecated macros (as opposed to 0/none
values that are still needed at the init and rpc layers, cf #27231).
cb58059 I agree the config option interface is WIP; Klement Tan who was working on it took a job that diverted him from contributing. It seems incongruent to have -debug
and -trace
options but only -debugexclude
. The plan discussed in one of the step PRs is to combine the functionality of the -debug
and (help-debug) -loglevel
options (perhaps to a renamed -log
config option, which would be more consistent naming-wise with the logging
RPC), and add log level functionality to that RPC. I haven't done that in the parent PR yet, so it's available to be done!
451f2e7 Ok for avoiding a mutex. I have had the nagging thought for a long time that it may not be inconceivable for some users to prefer logging only errors and warnings, thus to avoid coding ourselves into a corner regarding info
always being logged (which might apply to the preceding commit as well).
logging: Improve new LogDebug/Trace/Info/Warning/Error Macros Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
logging: Make new logging macros compatible with wallet code New logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318 aren't really useful in wallet code because wallet code because wallet code prefixes most log messages wi 8000 th the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
…always logged levels ec779a2 doc: add unconditional info loglevel following merge of PR 28318 (Jon Atack) Pull request description: Commit ab34dc6 of bitcoin#28318 was an incomplete version of [`118c756` (bitcoin#25203)](bitcoin@118c756) from the `Severity-based logging` parent PR. Add the missing text to update the `-loglevel` help doc. While here, make the help text a little easier to understand. Can be tested by running: ``` ./src/bitcoind -regtest -help-debug | grep -A12 loglevel= ``` before ``` -loglevel=<level>|<category>:<level> Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC: info, debug, trace (default=debug); warning and error levels are always logged. ``` after ``` -loglevel=<level>|<category>:<level> Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC. Possible values are info, debug, trace (default=debug). The following levels are always logged: error, warning, info. ``` ACKs for top commit: stickies-v: ACK ec779a2 Tree-SHA512: 0c375e30a5a4c168ca7d97720e8c287f598216767afedae329824e09a480830faf8537b792c5c4bb647c68681c287fe3005c62093708ce85624e9a71c8245e42
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Improve new LogDebug(), LogTrace(), LogInfo(), LogWarning(), LogError() macros introduced in bitcoin#28318: - Make them always accept log categories to make it possible to only log messages from a particular component. - Make them not rely on a global LogInstance, to provide better control of logging in controlled environments, such as unit tests that want to selectively capture log output, or libbitcoinkernel applications that want to have multiple instances of validation objects without mixing their log output. - Make them consistent, now all accepting the same parameters. - Make them less verbose by not requiring BCLog category constants to be specified in individual log prints
Disallow passing BCLog category constants to LogInfo(), LogWarning(), and LogError() macros, and disallow omitting BCLog categories when calling LogDebug() and LogTrace() macros. These restrictions have existed since the logging macros were added in bitcoin#28318 and not technically neccessary, but are believed to be useful to prevent log spam and prevent users from filtering out important messages based on category.
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogContext class inheriting from BCLog::Context which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages
Disallow passing BCLog category constants to LogInfo(), LogWarning(), and LogError() macros, and disallow omitting BCLog categories when calling LogDebug() and LogTrace() macros. These restrictions have existed since the logging macros were added in bitcoin#28318 and not technically neccessary, but are believed to be useful to prevent log spam and prevent users from filtering out important messages based on category.
Disallow passing BCLog category constants to LogInfo(), LogWarning(), and LogError() macros, and disallow omitting BCLog categories when calling LogDebug() and LogTrace() macros. These restrictions have existed since the logging macros were added in bitcoin#28318 and not technically neccessary, but are believed to be useful to prevent log spam and prevent users from filtering out important messages based on category.
Disallow passing BCLog category constants to LogInfo(), LogWarning(), and LogError() macros, and disallow omitting BCLog categories when calling LogDebug() and LogTrace() macros. These restrictions have existed since the logging macros were added in bitcoin#28318 and not technically neccessary, but are believed to be useful to prevent log spam and prevent users from filtering out important messages based on category. Co-Authored-By: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogContext class inheriting from BCLog::Context which can include the wallet name in log messages
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in bitcoin#28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogContext class inheriting from BCLog::Context which can include the wallet name in log messages
…always logged levels ec779a2 doc: add unconditional info loglevel following merge of PR 28318 (Jon Atack) Pull request description: Commit ab34dc6 of bitcoin#28318 was an incomplete version of [`118c756` (bitcoin#25203)](bitcoin@118c756) from the `Severity-based logging` parent PR. Add the missing text to update the `-loglevel` help doc. While here, make the help text a little easier to understand. Can be tested by running: ``` ./src/bitcoind -regtest -help-debug | grep -A12 loglevel= ``` before ``` -loglevel=<level>|<category>:<level> Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC: info, debug, trace (default=debug); warning and error levels are always logged. ``` after ``` -loglevel=<level>|<category>:<level> Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC. Possible values are info, debug, trace (default=debug). The following levels are always logged: error, warning, info. ``` ACKs for top commit: stickies-v: ACK ec779a2 Tree-SHA512: 0c375e30a5a4c168ca7d97720e8c287f598216767afedae329824e09a480830faf8537b792c5c4bb647c68681c287fe3005c62093708ce85624e9a71c8245e42
Replace
LogPrint*
functions with severity based logging functions:LogInfo(...)
,LogWarning(...)
,LogError(...)
for unconditional (uncategorised) logging (replacesLogPrintf
)LogDebug(CATEGORY, ...)
andLogTrace(CATEGORY, ...)
for conditional logging (replacesLogPrint
)LogPrintLevel(CATEGORY, LEVEL, ...)
for when the level isn't known in advance, or a category needs to be added for an info/warning/error log message (mostly unchanged, but rarely needed)Logs look roughly as they do now with
LogInfo
not having an[info]
prefix, andLogDebug
having a[cat]
prefix, rather than a[cat:debug]
prefix. This removesBCLog::Level::None
entirely -- forLogFlags::NONE
just useLevel::Info
, for any actual category, useLevel::Debug
.Adds docs to developer-notes about when to use which level.
Adds
-loglevelalways=1
option so that you get[net:debug]
,[all:info]
,[all:warning]
etc, which might be helpful for automated parsing, or just if you like everything to be consistent. Defaults to off to reduce noise in the default config, and to avoid unnecessary changes on upgrades.Changes the behaviour of
LogPrintLevel(CATEGORY, BCLog::Level::Info, ...)
to be logged unconditionally, rather than only being an additional optional logging level in addition to trace and debug. Does not change the behaviour ofLogPrintLevel(NONE, Debug, ...)
andLogPrintLevel(NONE, Trace, ...)
being no-ops.