ryanofsky
commented at 5:57 PM on June 26, 2024:
contributor
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 #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 util::log::Context which can include the wallet name in log messages.
This change makes -logsourcelocations usable with wallet code because it logs actual source locations instead of the WalletLogPrintf() location.
<!-- begin based-on -->
This is based on #34778 + #29256. The non-base commits are:
#34681 (wallet: refactor ScanForWalletTransactions by Eunovo)
#34617 (fees: wallet: remove block policy fee estimator internals from wallet by ismaelsadeeq)
#34514 (refactor: remove unnecessary std::move for trivially copyable types by l0rinc)
#34502 (wallet: remove most asserts of WALLET_FLAG_DESCRIPTORS flag by rkrux)
#34400 (wallet: parallel fast rescan (approx 5x speed up with 8 threads) by Eunovo)
#34193 (wallet: make migration more robust against failures by furszy)
#34075 (fees: Introduce Mempool Based Fee Estimation to reduce overestimation by ismaelsadeeq)
#33727 (zmq: Log bind error at Error level, abort startup on init error by isrod)
#28333 (wallet: Construct ScriptPubKeyMans with all data rather than loaded progressively by achow101)
#25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
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.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
in
src/wallet/wallet.h:448
in
5b30f17c22outdated
444 | @@ -444,6 +445,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
445 | */
446 | mutable RecursiveMutex cs_wallet;
447 |
448 | + WalletLogSource m_log;
Why not rename GetLogSource() -> Log() here and in WalletStorage and keep m_log private? I tried and it compiles as of 5b30f17c22ade44d301aed5051a398fa38251ef7.
Why not rename GetLogSource() -> Log() here and in WalletStorage and keep m_log private? I tried and it compiles as of 5b30f17.
Nice suggestion, implemented. This is much cleaner looking.
in
src/wallet/walletdb.cpp:553
in
5b30f17c22outdated
550 | }
551 |
552 | DatabaseCursor::Status status = cursor->Next(key, value);
553 | if (status != DatabaseCursor::Status::DONE) {
554 | - pwallet->WalletLogPrintf("Error: Unexpected legacy entry found in descriptor wallet %s. The wallet might have been tampered with or created with malicious intent.\n", pwallet->GetName()); 555 | + LogInfo(log, "Error: Unexpected legacy entry found in descriptor wallet %s. The wallet might have been tampered with or created with malicious intent.\n", pwallet->GetName());
Shouldn't this be a LogError/LogWarning with removed Error: -prefix?
Agree that makes sense. I implemented it in a followup commit so the main commit is still a refactoring that does not change behavior.
For now I did not remove "Error:" and "Warning:" prefixes because it would be a more significant, possibly unwelcome change, since the prefixes could help messages stand out, and might be relied upon by tests. I'm also not sure if the decision to include warning and error prefixes has been discussed before somewhere else. But I'm happy to change this if there is more feedback in support of it.
in
src/wallet/walletdb.cpp:987
in
5b30f17c22outdated
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.
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).
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?
in
src/wallet/wallet.cpp:2491
in
5b30f17c22outdated
LogInfo(m_log, "Error: -> LogError( here and in other places?
Thanks, done in a new commit (see earlier comment)
hodlinator
commented at 10:17 PM on June 26, 2024:
contributor
Went through this and the parent PR together. It was helpful to see how that other PR's changes were used in this one.
ryanofsky referenced this in commit 8de95b3b5d on Jun 27, 2024
ryanofsky referenced this in commit 5a629a60c4 on Jun 27, 2024
ryanofsky force-pushed on Jun 27, 2024
ryanofsky
commented at 4:13 AM on June 27, 2024:
contributor
Thanks for the review! The suggestions are a big improvement and make the logging code more succinct and clean.
Rebased 5b30f17c22ade44d301aed5051a398fa38251ef7 -> 5a629a60c4739b94383596f9d040502b7b2c8b69 (pr/gwlog.1 -> pr/gwlog.2, compare) on top of the updated parent PR implementing review suggestions.
ryanofsky referenced this in commit 1ac3f01fe5 on Jun 27, 2024
ryanofsky referenced this in commit db8c6fc2ca on Jun 27, 2024
ryanofsky force-pushed on Jun 27, 2024
DrahtBot added the label CI failed on Jun 27, 2024
DrahtBot
commented at 4:35 AM on June 27, 2024:
contributor
<!--85328a0da195eb286784d51f73fa0af9-->
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.
Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
Leave a comment here, if you need help tracking down a confusing failure.
ryanofsky
commented at 4:36 AM on June 27, 2024:
contributor
Updated 5a629a60c4739b94383596f9d040502b7b2c8b69 -> db8c6fc2ca5e1ad99aeda741e3b453f1f7bf7955 (pr/gwlog.2 -> pr/gwlog.3, compare) fixing initialization order bug in last push
DrahtBot removed the label CI failed on Jun 27, 2024
ryanofsky referenced this in commit 6b5b2354c6 on Jun 28, 2024
ryanofsky referenced this in commit d486e49b54 on Jun 28, 2024
ryanofsky referenced this in commit b0c2f8203d on Jun 28, 2024
ryanofsky referenced this in commit 29eaec25af on Jun 28, 2024
ryanofsky force-pushed on Jun 28, 2024
ryanofsky
commented at 2:27 PM on June 28, 2024:
contributor
Updated and rebased db8c6fc2ca5e1ad99aeda741e3b453f1f7bf7955 -> 29eaec25af32e543df3cff091938c3cb8f7cce17 (pr/gwlog.3 -> pr/gwlog.4, compare) with suggestion to use constexpr
Rebased 29eaec25af32e543df3cff091938c3cb8f7cce17 -> 0260cd5ccc3120102c001b3ab6c5f29dcf184b58 (pr/gwlog.4 -> pr/gwlog.5, compare) due to conflict with #30406
Rebased 0260cd5ccc3120102c001b3ab6c5f29dcf184b58 -> 0d49ada2b42e5b48b21bb7cb854851f09641abbb (pr/gwlog.5 -> pr/gwlog.6, compare) on top of updated base pr/bclog.20
Rebased 0d49ada2b42e5b48b21bb7cb854851f09641abbb -> f6b93a976b0127b55705dc33caf986a3344e12a4 (pr/gwlog.6 -> pr/gwlog.7, compare) due to conflict with #30485
Rebased f6b93a976b0127b55705dc33caf986a3344e12a4 -> 4c8fe044d3241664151b3727e31ac2eaa741b717 (pr/gwlog.7 -> pr/gwlog.8, compare) due to conflicts with #26619, #30659, and other PRs
Rebased 4c8fe044d3241664151b3727e31ac2eaa741b717 -> e8c6095c75dead138e79a18146ce865e7fe6529a (pr/gwlog.8 -> pr/gwlog.9, compare) due to conflicts with #31061
<!-- begin push-10 -->
Rebased e8c6095c75dead138e79a18146ce865e7fe6529a -> af6f854df0d0dd72b05cda4d2e1ed0d1c2c00738 (pr/gwlog.9 -> pr/gwlog.10, compare)<!-- end -->
<!-- begin push-11 -->
Rebased af6f854df0d0dd72b05cda4d2e1ed0d1c2c00738 -> 2e4d0c3b51e2e8fbf913f28361d1a0a8d1f3e166 (pr/gwlog.10 -> pr/gwlog.11, compare)<!-- end -->
<!-- begin push-12 -->
Rebased 2e4d0c3b51e2e8fbf913f28361d1a0a8d1f3e166 -> 186b721e6107a0606be6c55edbdd8ec5d5fabd2b (pr/gwlog.11 -> pr/gwlog.12, compare)<!-- end -->
Rebased df507121593d4a1cd58c80e5e63735c115c728c5 -> e84bd31c04751e968a0936b93d6cc7e639ac4409 (pr/gwlog.13 -> pr/gwlog.14, compare)<!-- end -->
<!-- begin push-15 -->
Rebased e84bd31c04751e968a0936b93d6cc7e639ac4409 -> 75042af2053485badea67b1ff9b38bc820f3f24c (pr/gwlog.14 -> pr/gwlog.15, compare)<!-- end -->
<!-- begin push-16 -->
Rebased 75042af2053485badea67b1ff9b38bc820f3f24c -> 74bb399dfa1f0823f26fc3bfa7917f5f4fa36668 (pr/gwlog.15 -> pr/gwlog.16, compare)<!-- end -->
<!-- begin push-17 -->
Rebased 74bb399dfa1f0823f26fc3bfa7917f5f4fa36668 -> a08c9bc808ef19accc90335fb115f791a66e0158 (pr/gwlog.16 -> pr/gwlog.17, compare)<!-- end --> on top of #29256 pr/bclog.34
<!-- begin push-18 -->
Rebased a08c9bc808ef19accc90335fb115f791a66e0158 -> aac55f94938aa7ac727b840a9766adb848e998ab (pr/gwlog.17 -> pr/gwlog.18, compare)<!-- end --> on top of #29256 pr/bclog.36
<!-- begin push-19 -->
Rebased aac55f94938aa7ac727b840a9766adb848e998ab -> 7fc95e7cbb3ee3cae14df02602ac51a3d910945c (pr/gwlog.18 -> pr/gwlog.19, compare)<!-- end --> on top of #29256 pr/bclog.37 with review suggestions
<!-- begin push-20 -->
Rebased 7fc95e7cbb3ee3cae14df02602ac51a3d910945c -> 524c5b8ef547700e4b5a234bf6bebd4d775d98e5 (pr/gwlog.19 -> pr/gwlog.20, compare)<!-- end --> on top of #29256 pr/bclog.39
<!-- begin push-21 -->
Rebased 524c5b8ef547700e4b5a234bf6bebd4d775d98e5 -> 45ecab65d4434aebafa23195c3571b833faf47ca (pr/gwlog.20 -> pr/gwlog.21, compare)<!-- end --> on top of #29256 pr/bclog.40
glozow added the label Wallet on Jul 2, 2024
DrahtBot added the label Needs rebase on Jul 11, 2024
ryanofsky referenced this in commit 5cec69a56e on Jul 17, 2024
ryanofsky referenced this in commit 57346e0dea on Jul 17, 2024
ryanofsky referenced this in commit b9a3715858 on Jul 17, 2024
ryanofsky referenced this in commit 0260cd5ccc on Jul 17, 2024
ryanofsky force-pushed on Jul 17, 2024
DrahtBot removed the label Needs rebase on Jul 17, 2024
DrahtBot
commented at 10:41 AM on July 22, 2024:
contributor
Make sure to run all tests locally, according to the documentation.
The failure may happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
</details>
DrahtBot added the label CI failed on Jul 22, 2024
DrahtBot removed the label CI failed on Jul 22, 2024
DrahtBot added the label Needs rebase on Jul 26, 2024
ryanofsky referenced this in commit c75687736a on Aug 7, 2024
ryanofsky referenced this in commit 0d51d583aa on Aug 7, 2024
ryanofsky force-pushed on Aug 7, 2024
ryanofsky referenced this in commit f16a846d79 on Aug 7, 2024
ryanofsky referenced this in commit 0d49ada2b4 on Aug 7, 2024
ryanofsky referenced this in commit 989f2ea404 on Aug 7, 2024
ryanofsky referenced this in commit f6b93a976b on Aug 7, 2024
ryanofsky referenced this in commit 5f6750a543 on Aug 7, 2024
ryanofsky referenced this in commit 517a4f1c0f on Aug 7, 2024
ryanofsky force-pushed on Aug 7, 2024
DrahtBot removed the label Needs rebase on Aug 7, 2024
DrahtBot added the label Needs rebase on Aug 15, 2024
ryanofsky referenced this in commit 8e9e7b90cd on Dec 9, 2024
ryanofsky referenced this in commit 4c8fe044d3 on Dec 9, 2024
ryanofsky referenced this in commit 980a494f6c on Dec 9, 2024
ryanofsky referenced this in commit 09fcfffd48 on Dec 9, 2024
ryanofsky force-pushed on Dec 9, 2024
DrahtBot removed the label Needs rebase on Dec 9, 2024
DrahtBot added the label Needs rebase on Jan 15, 2025
ryanofsky referenced this in commit b7e37883da on Mar 12, 2025
ryanofsky force-pushed on Mar 12, 2025
ryanofsky referenced this in commit e8c6095c75 on Mar 12, 2025
ryanofsky referenced this in commit 278ff86ca2 on Mar 12, 2025
ryanofsky referenced this in commit 6784d2baae on Mar 12, 2025
DrahtBot removed the label Needs rebase on Mar 12, 2025
ryanofsky referenced this in commit 6d0745d22b on Apr 3, 2025
ryanofsky referenced this in commit 1218acc259 on Apr 3, 2025
ryanofsky referenced this in commit af6f854df0 on Apr 3, 2025
ryanofsky force-pushed on Apr 3, 2025
ryanofsky referenced this in commit c3161fcac9 on Apr 3, 2025
ryanofsky referenced this in commit 4a10cb6ed9 on Apr 3, 2025
ryanofsky referenced this in commit 2be41ef85f on Apr 3, 2025
ryanofsky referenced this in commit eaac991552 on Apr 4, 2025
ryanofsky referenced this in commit c96e91eced on Apr 4, 2025
ryanofsky referenced this in commit a7266cfc9d on Apr 4, 2025
ryanofsky referenced this in commit e6f21513ed on Apr 4, 2025
ryanofsky force-pushed on Apr 4, 2025
ryanofsky referenced this in commit 2e4d0c3b51 on Apr 4, 2025
DrahtBot added the label CI failed on Apr 4, 2025
DrahtBot
commented at 3:37 AM on April 4, 2025:
contributor
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
</details>
DrahtBot removed the label CI failed on Apr 4, 2025
DrahtBot added the label Needs rebase on Apr 10, 2025
ryanofsky referenced this in commit 8e3ee9d7e7 on Oct 15, 2025
ryanofsky referenced this in commit b4c6b16c37 on Oct 15, 2025
ryanofsky referenced this in commit 9e7dabc35d on Oct 15, 2025
ryanofsky referenced this in commit 9e250970d2 on Oct 15, 2025
ryanofsky referenced this in commit 351ebaebf5 on Oct 15, 2025
ryanofsky referenced this in commit 158f6a6562 on Oct 15, 2025
ryanofsky referenced this in commit 186b721e61 on Oct 15, 2025
ryanofsky force-pushed on Oct 15, 2025
DrahtBot removed the label Needs rebase on Oct 15, 2025
ryanofsky referenced this in commit a5700c7911 on Oct 16, 2025
ryanofsky referenced this in commit 9a4310c644 on Oct 16, 2025
ryanofsky referenced this in commit e4ca362858 on Oct 16, 2025
ryanofsky referenced this in commit 98e2cef781 on Oct 16, 2025
ryanofsky referenced this in commit ffa668313a on Oct 16, 2025
ryanofsky referenced this in commit df50712159 on Oct 16, 2025
ryanofsky force-pushed on Oct 16, 2025
ryanofsky referenced this in commit 47332ca19b on Oct 16, 2025
ryanofsky referenced this in commit 8a4587f0c3 on Oct 16, 2025
DrahtBot added the label Needs rebase on Oct 31, 2025
ryanofsky referenced this in commit 9883750ab0 on Nov 10, 2025
ryanofsky referenced this in commit 09517b75a9 on Nov 10, 2025
ryanofsky referenced this in commit 6bbf29c5f8 on Nov 10, 2025
ryanofsky referenced this in commit 702a1d8257 on Nov 10, 2025
ryanofsky force-pushed on Nov 10, 2025
ryanofsky referenced this in commit 0f3c2338d8 on Nov 10, 2025
ryanofsky referenced this in commit e84bd31c04 on Nov 10, 2025
ryanofsky referenced this in commit 3babe4a45b on Nov 10, 2025
ryanofsky referenced this in commit a992199e44 on Nov 10, 2025
DrahtBot removed the label Needs rebase on Nov 11, 2025
DrahtBot added the label Needs rebase on Dec 6, 2025
ryanofsky referenced this in commit 7c49fcfc21 on Dec 12, 2025
ryanofsky referenced this in commit e4918d23b0 on Dec 12, 2025
ryanofsky referenced this in commit 2d0bc18b9f on Dec 12, 2025
ryanofsky referenced this in commit 526272c1f0 on Dec 12, 2025
ryanofsky referenced this in commit 161a936b4a on Dec 12, 2025
ryanofsky referenced this in commit a5704ff85c on Dec 12, 2025
ryanofsky force-pushed on Dec 12, 2025
ryanofsky referenced this in commit d3422488aa on Dec 12, 2025
ryanofsky referenced this in commit 75042af205 on Dec 12, 2025
DrahtBot removed the label Needs rebase on Dec 12, 2025
DrahtBot added the label Needs rebase on Dec 14, 2025
ryanofsky referenced this in commit fdcf06d4bb on Dec 16, 2025
ryanofsky referenced this in commit 049b0f6fca on Dec 16, 2025
ryanofsky referenced this in commit 90476d0bb5 on Dec 16, 2025
ryanofsky referenced this in commit e393af85aa on Dec 16, 2025
ryanofsky referenced this in commit b7e59129cf on Dec 16, 2025
ryanofsky force-pushed on Dec 16, 2025
ryanofsky referenced this in commit 74bb399dfa on Dec 16, 2025
ryanofsky referenced this in commit 97dce72d90 on Dec 16, 2025
ryanofsky referenced this in commit 1c80687bc2 on Dec 16, 2025
DrahtBot removed the label Needs rebase on Dec 16, 2025
DrahtBot added the label Needs rebase on Dec 18, 2025
ryanofsky referenced this in commit 5d43d4a39c on Jan 18, 2026
ryanofsky referenced this in commit cb2538a9b7 on Jan 18, 2026
ryanofsky referenced this in commit ac3938a2f4 on Jan 18, 2026
ryanofsky referenced this in commit 1634b44feb on Jan 18, 2026
ryanofsky referenced this in commit 05d22deffd on Jan 18, 2026
ryanofsky referenced this in commit 38b0c982b5 on Jan 18, 2026
ryanofsky referenced this in commit bb05a1a220 on Jan 18, 2026
ryanofsky referenced this in commit bb3f964dba on Jan 18, 2026
ryanofsky force-pushed on Jan 18, 2026
ryanofsky referenced this in commit 4fb99c22c1 on Jan 18, 2026
ryanofsky referenced this in commit a08c9bc808 on Jan 18, 2026
DrahtBot removed the label Needs rebase on Jan 18, 2026
l0rinc
commented at 4:51 PM on January 23, 2026:
contributor
I wanted to push a simple scripted diff to rename WalletLogPrintf, to LogInfo, but noticed this pR already does that (in a more elaborate way).
Is it a draft because it's based on #29256 which should be reviewed first? That one has two nacks, can you make a version of this that simply renames the leftover LogPrintf reference or is that just a demonstration for the usefulness of log contexts?
ryanofsky
commented at 5:48 PM on January 23, 2026:
contributor
Would be curious about your scripted-diff. I don't think we want to only replace WalletLogPrintf calls with LogInfo calls, because the point of WalletLogPrintf is to include wallet names in log messages, and it would bad to lose these, and awkward to have to specify them in every log call. I think this PR takes a nice approach of allowing Loginfo and other logging macros to work in wallet code including wallet names as part of the log context.
This PR is ready to review and has had some review, but is a draft because is based on another PR and should not be merged before that one. The other PR has nacks because originally it allowed LogInfo calls to accept category constants, and there was a debate about whether it was harmful to log category information, but I eventually gave in and removed it, so I don't think the nacks are still relevant.
DrahtBot added the label Needs rebase on Feb 4, 2026
ryanofsky referenced this in commit 3a73b718e4 on Feb 9, 2026
ryanofsky referenced this in commit c76a2be4eb on Feb 9, 2026
ryanofsky referenced this in commit 2819b6d067 on Feb 9, 2026
ryanofsky referenced this in commit daeeb2042f on Feb 9, 2026
ryanofsky referenced this in commit 8714e10178 on Feb 9, 2026
ryanofsky referenced this in commit fd8d0a1039 on Feb 9, 2026
ryanofsky referenced this in commit 20f4088260 on Feb 9, 2026
ryanofsky referenced this in commit ac12a998ca on Feb 9, 2026
ryanofsky referenced this in commit f503957457 on Feb 9, 2026
ryanofsky referenced this in commit aac55f9493 on Feb 9, 2026
ryanofsky force-pushed on Feb 9, 2026
DrahtBot removed the label Needs rebase on Feb 9, 2026
Block rvalue Source in compile time by deleting the overload
Assuming this change is intended to address the temporary lifetime issue pointed out in your other comment, I think this could make sense. Replied to that comment directly, though here
adyshimony
commented at 4:03 AM on March 1, 2026:
none
Reviewed and tested aac55f94938a.
I found an issue, at log.h LogPrint_ , rvalue source arguments can be bound by reference and used after their lifetime ends. I tried to solve this in a few ways, but I think the most elegant simple one is to block rvalues at compile time by deleting the overload. I failed to find any rvalue usage that exists today. Solution suggested in inline comments.
I used the following test to confirm the lifetime issue (for demo of the issue only; we don't need it if we block rvalues at compile time):
Isn't that a happy flow? Maybe we can use LogInfo here?
Makes sense, and now dropped this commit since the code has changed since it was written. (It looks like the original version of this commit 5a629a60c4739b94383596f9d040502b7b2c8b69 did have the same mistake.)
ryanofsky referenced this in commit 5f5ac95167 on Mar 2, 2026
ryanofsky referenced this in commit fab63e17b7 on Mar 2, 2026
ryanofsky referenced this in commit ee3fb8cf39 on Mar 2, 2026
ryanofsky referenced this in commit a2a2bd7898 on Mar 2, 2026
ryanofsky referenced this in commit 89223d52db on Mar 2, 2026
ryanofsky referenced this in commit ba41e5e0fd on Mar 2, 2026
ryanofsky referenced this in commit 7fc95e7cbb on Mar 2, 2026
ryanofsky force-pushed on Mar 2, 2026
adyshimony
commented at 12:10 AM on March 3, 2026:
none
ryanofsky
commented at 6:00 PM on March 3, 2026:
contributor
Thanks for the reviews @adyshimony! Note that most of your comments apply to #29256 which this is based on (#29256 is subset of this PR), so you may be interested in reviewing that directly. Some of your comments are now addressed in recent updates to both PRs.
I found an issue, at log.h LogPrint_ , rvalue source arguments can be bound by reference and used after their lifetime ends.
I think this issue is already handled by the LIFETIMEBOUND annotation in GetSource().
When I build your test, the compiler shows warning: temporary bound to local reference '_source' will be destroyed at the end of the full-expression [-Wdangling] on line LogDebug(make_source(), "temporary %s", "source");.
So I think any code written in that unsafe style should be caught locally or by CI, and not be an issue. Your suggestion #30343 (review) to restrict GetSource() overloading so it can't bind to lvalues could also make sense if LIFETIMEBOUND warning isn't sufficient, but I feel like just using LIFETIMEBOUND avoids unnecessary complexity and provides a better diagnostic.
adyshimony
commented at 11:54 AM on March 4, 2026:
none
Ohhh, I didn’t catch this earlier because I was building with GCC!
After switching to Clang, I can see it.
This is Clang only flag, so reviewers using only GCC may miss it...
I still think the cleaner approach is to reject temporary sources directly at compile time by deleting the rvalue overload, so it clearly says "this usage is not allowed".
Given the existing lvalue overload, the additional deleted overload can be simple:
Test that LogInfo/LogWarning/LogError always evaluate their arguments
even when logging is disabled.
ajtowns pointed out this behavior was important and could affect non-logging
code if changed in
https://github.com/bitcoin/bitcoin/pull/34374#discussion_r2734793117
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
3ea39b9f21
logging: declare LogAcceptCategory in util
Move LogAcceptCategory from logging.h to util/log.h without changing
behavior. Also call LogAcceptCategory instead of ShouldLog in
validationinterface.cpp.
LogAcceptCategory is the stable API for determining if log messages
should be emitted by application code. ShouldLog is a lower-level hook
implemented by the log handling backend which takes an opaque category
argument instead of an enum.
Also add some test coverage on LogAcceptCategory.
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
4ad8e0e206
log test: Add test for all accepted logging arguments
Add new logging test to call macros with all allowed combinations of macro
arguments.
The new test replaces a less comprehensive test that doesn't cover log
statements without format arguments. It's also moved to the top of the test
suite because it's a good illustration of what typical log prints look like,
what logging calls are allowed and disallowed, and what the resulting log
output looks like.
8a3d10759b
log refactor: Ensure categories are not logged at info and higher levels
Previously this used to be possible through the LogPrintLevel call but now that
call is removed, this change is just an internal refactoring and has no visible
effect except in tests.
c53ded9860
log refactor: log macro rewrite
Rewrite log macros to fix a number of issues: lack of control over rate
limiting, unnecessary strprintf calls during fuzzing, confusing error messages
when macros are called with the wrong arguments.
Since this is a rewrite, reading the new code in log.h first should be clearer
than starting from the diff.
Specific benefits of the new implementation are:
- Functionality is implemented once in a single `LOG_EMIT` macro instead of
multiple times in different macros with diverging code paths and unexplained
differences.
- `LogPrintLevel_` hack used to bypass rate limiting is dropped. The `LOG_EMIT`
macro can control rate limiting (and other options if they are added in the
future) while still using the same rate-limiting defaults as other macros.
- Unnecessary `strprintf` calls are now skipped when logging is disabled (in
bitcoind when `-noprinttoconsole -nodebuglogfile` options are used, and in
tests and kernel applications when DisableLogging is called). This change
should not affect bitcoind noticeably, but could speed up fuzz tests calling
functions which log.
- Clearer error messages: If you pass a category to a macro which does not
accept it, or forget to pass a category to a macro which requires it, you
will see a direct message telling you to add or remove the category instead
of expanded macro syntax errors.
- Previously you could call `LogPrintLevel_` to bypass restrictions on passing
category arguments. New `LOG_EMIT` macro has the same requirements as the
other macros and shows the same compile-time errors.
- Previously "always evaluate arguments" behavior at Info and higher levels
looked accidental and was undocumented
(https://github.com/bitcoin/bitcoin/pull/34374#discussion_r2734793117). Now
the behavior is documented and explicit.
- Previously `detail_LogIfCategoryAndLevelEnabled` would assert at runtime
if it was called at a disallowed level. Now all checking is done at
compile time.
Co-Authored-By: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Co-Authored-By: stickies-v <stickies-v@protonmail.com>
fbc43e5b66
Merge branch 'pr/relog' into pr/bclogfd61946f1f
log refactor: Allow log macros to accept context arguments
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:
- https://github.com/bitcoin/bitcoin/pull/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.
- https://github.com/bitcoin/bitcoin/pull/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>
Co-Authored-By: stickies-v <stickies-v@protonmail.com>
9a9f683c1b
doc: Add documentation about log levels and macrosdddac91a7a
log refactor: Add support for custom log contexts
Custom log contexts allow overridding log formatting and adding metadata, such
as request ids or wallet names to log messages, while still using standard
macros for logging. This is used to replace WalletLogPrintf() functions with
LogInfo() calls in followup PR #30343.
551a030b6f
Merge branch 'pr/bclog' into pr/gwlog47fbf07b48
wallet, logging: Replace WalletLogPrintf() with LogInfo()
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 #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
ef93a88845
wallet, logging: Switch LogInfo to LogWarning/LogError
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.
Suggested by hodlinator in
https://github.com/bitcoin/bitcoin/pull/30343#discussion_r1655406670
https://github.com/bitcoin/bitcoin/pull/30343#discussion_r1655407301
https://github.com/bitcoin/bitcoin/pull/30343#discussion_r1655436010
45ecab65d4
ryanofsky referenced this in commit 1a8958da29 on Apr 1, 2026
ryanofsky referenced this in commit beca2d427e on Apr 1, 2026
ryanofsky referenced this in commit eb67f3fd38 on Apr 1, 2026
ryanofsky force-pushed on Apr 1, 2026
DrahtBot removed the label Needs rebase on Apr 1, 2026
DrahtBot added the label Needs rebase on Apr 23, 2026
DrahtBot
commented at 12:54 PM on April 23, 2026:
contributor
<!--cf906140f33d8803c4a75a2196329ecb-->
🐙 This pull request conflicts with the target branch and needs rebase.
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-05-02 18:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me