-
Notifications
You must be signed in to change notification settings - Fork 37.8k
wallet, logging: Replace WalletLogPrintf() with LogInfo() #30343
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
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30343. ReviewsSee the guideline for information on the review process. 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. |
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.
Went through this and the parent PR together. It was helpful to see how that other PR's changes were used in this one.
src/wallet/wallet.cpp
Outdated
@@ -3866,13 +3868,13 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat | |||
AssertLockHeld(cs_wallet); | |||
|
|||
if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { | |||
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n"); | |||
LogInfo(m_log, "Cannot add WalletDescriptor to a non-descriptor wallet\n"); |
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 maybe have been a warning all along?
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.
re: #30343 (comment)
Should maybe have been a warning all along?
Good catch. It actually looks to me like all of the log prints in this function should be errors. I changed them to use LogError in a new commit. It's a separate commit because the level change is a minor change in behavior, and is less obvious than other level changes.
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.
Are you sure that LogError
is the right level? It should only be used for fatal errors where the node needs to shut down, according to the docs. This seems like a warning here, as suggested above.
Some wallet code can probably use Result
and pass errors up, possibly here as well. And the caller can decide whether to log as a warning or return over RPC (or something else).
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.
Are you sure that
LogError
is the right level? It should only be used for fatal errors where the node needs to shut down, according to the docs. This seems like a warning here, as suggested above.
Oh, that is interesting. The descriptions of those log levels in https://github.com/bitcoin/bitcoin/blob/b27afb7fb774809c9c075d56e44657e0b607a00c/doc/developer-notes.md#logging are much more severe than I would have expected. Based on those descriptions I would expect LogError to be called LogFatal and LogWarning to be called LogCritical. I would have expected LogError to be used for normal errors, and LogWarning to be used for normal warnings.
Maybe the naming would be worth following up on, but I don't think it would be good to do in this PR. It actually seems like LogInfo is the right log level to use here, not LogWarning. Or do you disagree? Should I just drop the last two commits in this PR?
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
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 for the review! The suggestions are a big improvement and make the logging code more succinct and clean.
Rebased 5b30f17 -> 5a629a6 (pr/gwlog.1
-> pr/gwlog.2
, compare) on top of the updated parent PR implementing review suggestions.
src/wallet/wallet.cpp
Outdated
@@ -3866,13 +3868,13 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat | |||
AssertLockHeld(cs_wallet); | |||
|
|||
if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { | |||
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n"); | |||
LogInfo(m_log, "Cannot add WalletDescriptor to a non-descriptor wallet\n"); |
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.
re: #30343 (comment)
Should maybe have been a warning all along?
Good catch. It actually looks to me like all of the log prints in this function should be errors. I changed them to use LogError in a new commit. It's a separate commit because the level change is a minor change in behavior, and is less obvious than other level changes.
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
Updated 5a629a6 -> db8c6fc ( |
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
Updated and rebased db8c6fc -> 29eaec2 ( |
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
Test will be extended in next commit to cover support for context objects.
Allow LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() macros to accept context arguments to provide more information in log messages and more control over logging to callers. This functionality is used in followup PRs: - bitcoin#30342 - To let libbitcoinkernel send output to specfic `BCLog::Logger` instances instead of a global instance, so output can be disambiguated and applications can have more control over logging. - bitcoin#30343 - To replace custom `WalletLogPrintf` calls with standard logging calls that automatically include wallet names and don't log everything at info level. This commit does not change behavior of current log prints or require them to be updated. It includes tests and documentation covering the new functionality. Co-Authored-By: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Needed to fix errors like: const Context &GetContext(const Context &)': expects 1 arguments - 3 provided due to a compiler bug: https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly/5134656#5134656 Example CI failure: https://github.com/bitcoin/bitcoin/actions/runs/8072891468/job/22055528830?pr=29256
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
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
Allow LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() macros to accept context arguments to provide more information in log messages and more control over logging to callers. This functionality is used in followup PRs: - bitcoin#30342 - To let libbitcoinkernel send output to specfic `BCLog::Logger` instances instead of a global instance, so output can be disambiguated and applications can have more control over logging. - bitcoin#30343 - To replace custom `WalletLogPrintf` calls with standard logging calls that automatically include wallet names and don't log everything at info level. This commit does not change behavior of current log prints or require them to be updated. It includes tests and documentation covering the new functionality.
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
Allow LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() macros to accept context arguments to provide more information in log messages and more control over logging to callers. This functionality is used in followup PRs: - bitcoin#30342 - To let libbitcoinkernel send output to specfic `BCLog::Logger` instances instead of a global instance, so output can be disambiguated and applications can have more control over logging. - bitcoin#30343 - To replace custom `WalletLogPrintf` calls with standard logging calls that automatically include wallet names and don't log everything at info level. This commit does not change behavior of current log prints or require them to be updated. It includes tests and documentation covering the new functionality.
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in bitcoin#30343 (comment) bitcoin#30343 (comment) bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use the corresponding log level. Change suggested by hodlinator in bitcoin#30343 (comment)
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
🐙 This pull request conflicts with the target branch and needs rebase. |
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
1 similar comment
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
Make new logging macros
LogDebug()
,LogTrace()
,LogInfo()
,LogWarning()
, andLogError()
compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in #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 newWalletLogSource
class inheriting fromBCLog::Source
which can include the wallet name in log messages.This is based on #29256. The non-base commits are:
fea5da15eef4
wallet, logging: Replace WalletLogPrintf() with LogInfo()e6f21513edec
wallet, logging: Switch LogInfo to LogWarning/LogError2e4d0c3b51e2
wallet, logging: Switch LogInfo to LogError in AddWalletDescriptor