mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
logging: make trace logging easily usable #35387
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35387
Loading…
Reference in a new issue
No description provided.
Delete branch "pr/loglevel"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: Currently it is difficult to enable
tracelogging.The
-loglevel=tracesetting works, but does nothing by default and needs to be combined with-debugsettings to have an effect.Additionally, it is not possible to switch between
debugandtracelogging at runtime without restarting the node. These problems maketracelogging less useful than it could be, effectively make existingtracelogs undiscoverable, and making it not worthwhile to add new tracing.Solution: Fix these issues by allowing the
-logleveloption to work without an accompanying-debugoption, and by adding a matchingloglevelRPC that allows log levels to be configured at runtime.Usage examples:
Compatibility: This PR is backwards compatible and doesn't change the
-debugand-debugexcludeoptions (which become synonyms for-loglevel=debugand-loglevel=info, respectively). TheloggingRPC is also mostly unchanged, except now it validates category names before updating log levels, instead of failing with half-applied changes. Also theloggingRPC now only toggles betweeninfoanddebuglevels instead of trying to remember previously assigned levels, which was needlessly confusing.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
Reviewers, 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.
LLM Linter (✨ experimental)
Possible places where comparison-specific test macros should replace generic comparisons:
test/functional/feature_logging.pyassert result['net'] == 'trace'/assert result['http'] == 'info'-> useassert_equal(result['net'], 'trace')andassert_equal(result['http'], 'info')test/functional/feature_logging.pyassert result['net'] == 'debug'-> useassert_equal(result['net'], 'debug')test/functional/feature_logging.pyassert result['net'] == 'info'-> useassert_equal(result['net'], 'info')test/functional/feature_logging.pyassert result['net'] == 'trace'/assert result['http'] == 'info'(in theall='info', net='trace'block) -> useassert_equal(...)for each comparisontest/functional/feature_logging.pyassert result['net'] == 'info'/assert result['http'] == 'trace'(in theall='trace', net='info'block) -> useassert_equal(...)for each comparisontest/functional/feature_logging.pyassert active == expected_active, f"Inconsistency for {cat}: logging={active}, loglevel={levels_result[cat]}"-> useassert_equal(active, expected_active, f"...")2026-07-14 00:37:40
🚧 At least one of the CI tasks failed.
Task
macOS native, fuzz: https://github.com/bitcoin/bitcoin/actions/runs/26473571406/job/77953158807LLM reason (✨ experimental): CI failed because the fuzz target
rpccrashed on an unknown RPC commandloglevel(not listed inRPC_COMMANDS_SAFE_FOR_FUZZING/RPC_COMMANDS_NOT_SAFE_FOR_FUZZING), causing exit code -6.Hints
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.
Updated 2e4ac6d568af2ae0bf3e81748ba1a63d0cdb71b8 -> 828a0287fa194b7b94e600a10e06e21f74434366 (
pr/loglevel.2->pr/loglevel.3, compare) to fix clang-tidy and other ci errors https://github.com/bitcoin/bitcoin/actions/runs/26473571406/job/77954549771?pr=35387Rebased 828a0287fa194b7b94e600a10e06e21f74434366 -> bcf1c44df17a2c6ec3ff04582ee435b67cf2f187 (
pr/loglevel.3->pr/loglevel.4, compare) due to conflict with #34411 (Full Libevent removal)Rebased bcf1c44df17a2c6ec3ff04582ee435b67cf2f187 ->
dffb8cf9e7(pr/loglevel.4->pr/loglevel.5, compare) due to conflict with #35597This looks like an elegant approach, I think it's an intuitive RPC and
-loglevelinterface. The PR description should probably reference #34038 as an alternativate?I don't think we should have 2 parallel active logging RPC methods, so imo this PR should mark
loggingdeprecated, and we should keep it around for a long time as it's probably heavily used.nit: the
MaybeArghelper is better suited here:git diff on 828a0287fa
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
5 additional verified findings in the full report.
🔴 Major · Unknown categories in a
categoriesobject dereference an empty optionalA positional or explicit
categoriesobject with an unknown key can trigger undefined behavior instead of an invalid-parameter error; only an authenticated RPC client can make this call.Location:
src/rpc/node.cpp:273(head).🟠 Minor · A config-file global
logleveloverrides per-category command-line levelsBecause config-file values are applied after command-line values, a global level in the config can silently erase a command-line
-loglevel=<category>:<level>override.Location:
src/init/common.cpp:85(head).🟠 Minor · An
infocategory level prevents the default debug-log shrink-loglevel=<category>:infoleaves the category enabled even though it blocks debug and trace output, unlike the-debugexcludeequivalent described in the release notes.Location:
src/init/common.cpp:98(head).🟠 Minor · The
libeventexamples for theloglevelRPC are rejectedTwo documented commands return an "Unknown named parameter" error because
libeventis not a valid named category.Location:
doc/release-notes-35387.md:25(head).🟠 Minor · The test fixture's
-loglevel=tracere-enables logging in no-log and benchmark setupsIn fuzz and benchmark setups, the built-in
-loglevel=tracenow re-enables categories after-nodebugor-debug=0, changing what those contexts measure.Location:
src/init/common.cpp:89(head).🟠 Minor · The
all:<level>forms apply the default threshold instead of the requested levelAccepted forms such as
all:info,1:info, and:infoenable all categories at the default Debug threshold, so they can turn on debug logging instead of applying the requested level.Location:
src/init/common.cpp:97(head).Reviewed:
dffb8cf9e7bd· Full review report · Previous reports@ryanofsky can you respond to @stickies-v's comments?
I think this RPC would be easier to use and reason about if we split it into a read and a write method, where the write method makes a single change per call:
getlogconfig-> see current log levels (under alevelskey, so we can add other runtime log options later without breaking anything)setloglevel <level>-> set global log levelsetloglevel <level> <category>-> set category levelFor example, consider
bitcoin rpc loglevel zmq=info trace. It's not obvious (and not documented) what the log level ofzmqis going to be after this call:infoortrace? If every call makes just one change, the user sorts priorities, and we keep the interface easier to understand while limiting implementation complexity and test surface (no moreOBJ_NAMED_PARAMS, dynamically generated args, or client conversion entry). Furthermore, it makes it easier to upgrade the RPC later if we need to.It also aligns much better with the new OpenRPC spec. Params are described independently, so the schema can't express precedence or mutual exclusion between them. With
setloglevel, every request that's valid according to the schema has exactly one meaning, and the signature doesn't change whenever a category is added. Splitting read and write also makes side effects obvious from the method name, and lets-rpcwhitelistgrant read-only access. The main downside is that the schema no longer lists the valid categories, at least untilRPCArgsupports enums.Being able to set multiple levels in a single command is convenient on the CLI, but I think that's a CLI concern rather than an RPC one: RPC clients can just make multiple calls (or use a JSON-RPC batch), and I don't think atomicity is meaningful for logging.
git diff on 828a0287fa
diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp
index 98c2557a18..a28543fb3b 100644
--- a/src/rpc/client.cpp
+++ b/src/rpc/client.cpp
@@ -334,7 +334,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "psbtbumpfee", 1, "psbt_version"},
{ "logging", 0, "include" },
{ "logging", 1, "exclude" },
{ "disconnectnode", 1, "nodeid" },
{ "gethdkeys", 0, "active_only" },
{ "gethdkeys", 0, "options" },
diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp
index 6de4562495..4c45ed129a 100644
--- a/src/rpc/node.cpp
+++ b/src/rpc/node.cpp
@@ -220,72 +220,80 @@ static void UpdateLogCategories(std::vector<std::pair<BCLog::LogFlags, BCLog::Le
}
}
-static RPCMethod loglevel()
+static UniValue LogLevelsToJSON()
{
+}
+static RPCResult LogLevelsResult(std::string key_name)
+{
+}
+
+static RPCMethod getlogconfig()
+{
{
+},
+}
+static RPCMethod setloglevel()
+{
+{
},
};
}
@@ -301,7 +309,7 @@ static RPCMethod logging()
"The valid logging categories are: " + LogInstance().LogCategoriesString() + "\n"
"In addition, the following are available as category names with special meanings:\n"
" - "all", "1" : represent all logging categories.\n"
@@ -489,8 +497,9 @@ void RegisterNodeRPCCommands(CRPCTable& t)
{
static const CRPCCommand commands[]{
{"control", &getmemoryinfo},
diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp
index c81156a164..548e08f5bf 100644
--- a/src/test/fuzz/rpc.cpp
+++ b/src/test/fuzz/rpc.cpp
@@ -135,6 +135,7 @@ const std::vectorstd::string RPC_COMMANDS_SAFE_FOR_FUZZING{
"getdescriptorinfo",
"getdifficulty",
"getindexinfo",
"getmemoryinfo",
"getmempoolancestors",
"getmempooldescendants",
@@ -163,7 +164,6 @@ const std::vectorstd::string RPC_COMMANDS_SAFE_FOR_FUZZING{
"joinpsbts",
"listbanned",
"logging",
"mockscheduler",
"ping",
"preciousblock",
@@ -174,6 +174,7 @@ const std::vectorstd::string RPC_COMMANDS_SAFE_FOR_FUZZING{
"scantxoutset",
"sendmsgtopeer", // when no peers are connected, no p2p message is sent
"sendrawtransaction",
"setmocktime",
"setnetworkactive",
"signmessagewithprivkey",
diff --git a/test/functional/feature_logging.py b/test/functional/feature_logging.py
index 9d6ea2be35..1f41f3e0b1 100755
--- a/test/functional/feature_logging.py
+++ b/test/functional/feature_logging.py
@@ -9,7 +9,10 @@ import os
from test_framework.test_framework import BitcoinTestFramework
from test_framework.p2p import P2PInterface
from test_framework.test_node import ErrorMatch
-from test_framework.util import assert_raises_rpc_error
+from test_framework.util import (
+)
class LoggingTest(BitcoinTestFramework):
@@ -160,66 +163,59 @@ class LoggingTest(BitcoinTestFramework):
p2p.wait_for_verack()
self.nodes[0].disconnect_p2ps()
if name == 'main':
LoggingTest(file).main()
At startup, I think it makes sense for
-loglevelto be declarative (unlike the RPC, which is imperative).<category>:<level>always overrides a less specific global<level>, regardless of ordering (or source*). If the same key is specified multiple times, the last occurrence should take precedence (taking into account source*).E.g.
-loglevel=net:trace -loglevel=debug, orloglevel=debuginbitcoin.confwith-loglevel=net:traceon CLI, should yieldtracefornetanddebugfor everything else, but this PR makes everythingdebug.Keeping it declarative is also simpler: it removes the "global level must be specified first" error, and a global level doesn't need to reset anything.
*
bitcoin.confvs CLI. For the same key,bitcoin.confcurrently takes precedence over CLI (already the case on master). I think that's a separate issue, probably best fixed generically inArgsManager, so leaving that out of scope here).Tested
dffb8cfagainst masterdb0bde16, runningbitcoinddirectly (without the test framework's default-loglevel=trace) and reading the state back with theloggingandloglevelRPCs.-debugcombined with-loglevelbehaves differently. The description says the PR is backwards compatible and doesn't change-debug, and on master the-loglevelhelp says it sets the level "for logging categories enabled with the -debug configuration option or the logging RPC". With this PR a global-logleveltoken enables or disables all categories and overrides-debug:-debug=net -loglevel=tracenetenabled-loglevel=trace -nodebug-debug=http -debug=0 -loglevel=trace-loglevel=info -debug=netnetenabledThe PR adds
-nologlevelto the existing-debug=0test infeature_logging.pyfor this reason ("-nologlevel clears the test framework's -loglevel=trace which would otherwise ..."). Is this intended? If so, could the release notes mention it and the description drop "backwards compatible"?+1 to stickies-v's
bitcoin.confexample. With-loglevel=net:traceon the command line andloglevel=debugin the config file,netends up atdebughere.Nit: both release-notes examples with
libevent(doc/release-notes-35387.md:25-26) fail withUnknown named parameter libevent.