Skip to content

Commit c60c49b

Browse files
committed
Improve help text and behavior of RPC-logging
A) The changes in behavior are as follows: 1. Introduce logging category "none" as alias of "0" for both RPC-logging and bitcoind "-debug" parameter. 2. Same as "0" is given to argument of "-debug", if "none" or "0" is given to <include>, all other given logging categories are ignored. The same is true for <exclude>. (Before this PR, "0" was accepted but just be ignored itself.) B) The changes in the help text are as follows: 1. Add a descrption about the evaluation order of <include> and <exclude> to clarify how debug loggig categories to be set. 2. Delete text that describe restriction about libevent because it's already allowed libevent logging to be updated during runtime. 3. Add a description for category "all", "1", "none" and "0". 4. Add "optional" to the help text of <include> and <exclude>. 5. Add missing new lines before "Argument:". 6. This RPC always returns all logging categories with status. Fix the help text to match this behavior.
1 parent a90e6d2 commit c60c49b

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ bool AppInitParameterInteraction()
925925
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
926926
const std::vector<std::string> categories = gArgs.GetArgs("-debug");
927927

928-
if (find(categories.begin(), categories.end(), std::string("0")) == categories.end()) {
928+
if (std::none_of(categories.begin(), categories.end(),
929+
[](std::string cat){return cat == "0" || cat == "none";})) {
929930
for (const auto& cat : categories) {
930931
uint32_t flag = 0;
931932
if (!GetLogCategory(&flag, &cat)) {

src/rpc/misc.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ uint32_t getCategoryMask(UniValue cats) {
577577
if (!GetLogCategory(&flag, &cat)) {
578578
throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown logging category " + cat);
579579
}
580+
if (flag == BCLog::NONE) {
581+
return 0;
582+
}
580583
mask |= flag;
581584
}
582585
return mask;
@@ -586,16 +589,32 @@ UniValue logging(const JSONRPCRequest& request)
586589
{
587590
if (request.fHelp || request.params.size() > 2) {
588591
throw std::runtime_error(
589-
"logging [include,...] <exclude>\n"
592+
"logging ( <include> <exclude> )\n"
590593
"Gets and sets the logging configuration.\n"
591-
"When called without an argument, returns the list of categories that are currently being debug logged.\n"
592-
"When called with arguments, adds or removes categories from debug logging.\n"
594+
"When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
595+
"When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
596+
"The arguments are evaluated in order \"include\", \"exclude\".\n"
597+
"If an item is both included and excluded, it will thus end up being excluded.\n"
593598
"The valid logging categories are: " + ListLogCategories() + "\n"
594-
"libevent logging is configured on startup and cannot be modified by this RPC during runtime."
595-
"Arguments:\n"
596-
"1. \"include\" (array of strings) add debug logging for these categories.\n"
597-
"2. \"exclude\" (array of strings) remove debug logging for these categories.\n"
598-
"\nResult: <categories> (string): a list of the logging categories that are active.\n"
599+
"In addition, the following are available as category names with special meanings:\n"
600+
" - \"all\", \"1\" : represent all logging categories.\n"
601+
" - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
602+
"\nArguments:\n"
603+
"1. \"include\" (array of strings, optional) A json array of categories to add debug logging\n"
604+
" [\n"
605+
" \"category\" (string) the valid logging category\n"
606+
" ,...\n"
607+
" ]\n"
608+
"2. \"exclude\" (array of strings, optional) A json array of categories to remove debug logging\n"
609+
" [\n"
610+
" \"category\" (string) the valid logging category\n"
611+
" ,...\n"
612+
" ]\n"
613+
"\nResult:\n"
614+
"{ (json object where keys are the logging categories, and values indicates its status\n"
615+
" \"category\": 0|1, (numeric) if being debug logged or not. 0:inactive, 1:active\n"
616+
" ...\n"
617+
"}\n"
599618
"\nExamples:\n"
600619
+ HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
601620
+ HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")

src/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct CLogCategoryDesc
220220
const CLogCategoryDesc LogCategories[] =
221221
{
222222
{BCLog::NONE, "0"},
223+
{BCLog::NONE, "none"},
223224
{BCLog::NET, "net"},
224225
{BCLog::TOR, "tor"},
225226
{BCLog::MEMPOOL, "mempool"},

0 commit comments

Comments
 (0)