Skip to content

Commit ef14f2e

Browse files
committed
Merge #11191: RPC: Improve help text and behavior of RPC-logging.
c60c49b Improve help text and behavior of RPC-logging (Akio Nakamura) Pull request description: 1. It is allowed `libevent` logging to be updated during runtime, but still described that restriction in the help text. So we delete these text. 2. Add a descrption about the evaluation order of `<include>` and `<exclude>` to clarify how debug loggig categories to be set. 3. Add a description about the available logging category `"all"` which is not explained. 4. Add `"optional"` to the help text of `<include>` and `<exclude>`. 5. Add missing new lines before `"Argument:"`. 6. `"0"`,`"1"` are allowed in both array of `<include>` and `<exclude>`. `"0"` is **ignored** and `"1"` is treated **same as** `"all"`. It is confusing, so forbid them. 7. It always returns all logging categories with status. Fix the help text to match this behavior. Tree-SHA512: c2142da1a9bf714af8ebc38ac0d82394e2073fc0bd56f136372e3db7b2af3b6746f8d6b0241fe66c1698c208c124deb076be83f07dec0d0a180ad150593af415
2 parents 6d3dc52 + c60c49b commit ef14f2e

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
@@ -919,7 +919,8 @@ bool AppInitParameterInteraction()
919919
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
920920
const std::vector<std::string> categories = gArgs.GetArgs("-debug");
921921

922-
if (find(categories.begin(), categories.end(), std::string("0")) == categories.end()) {
922+
if (std::none_of(categories.begin(), categories.end(),
923+
[](std::string cat){return cat == "0" || cat == "none";})) {
923924
for (const auto& cat : categories) {
924925
uint32_t flag = 0;
925926
if (!GetLogCategory(&flag, &cat)) {

src/rpc/misc.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ uint32_t getCategoryMask(UniValue cats) {
533533
if (!GetLogCategory(&flag, &cat)) {
534534
throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown logging category " + cat);
535535
}
536+
if (flag == BCLog::NONE) {
537+
return 0;
538+
}
536539
mask |= flag;
537540
}
538541
return mask;
@@ -542,16 +545,32 @@ UniValue logging(const JSONRPCRequest& request)
542545
{
543546
if (request.fHelp || request.params.size() > 2) {
544547
throw std::runtime_error(
545-
"logging [include,...] <exclude>\n"
548+
"logging ( <include> <exclude> )\n"
546549
"Gets and sets the logging configuration.\n"
547-
"When called without an argument, returns the list of categories that are currently being debug logged.\n"
548-
"When called with arguments, adds or removes categories from debug logging.\n"
550+
"When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
551+
"When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
552+
"The arguments are evaluated in order \"include\", \"exclude\".\n"
553+
"If an item is both included and excluded, it will thus end up being excluded.\n"
549554
"The valid logging categories are: " + ListLogCategories() + "\n"
550-
"libevent logging is configured on startup and cannot be modified by this RPC during runtime."
551-
"Arguments:\n"
552-
"1. \"include\" (array of strings) add debug logging for these categories.\n"
553-
"2. \"exclude\" (array of strings) remove debug logging for these categories.\n"
554-
"\nResult: <categories> (string): a list of the logging categories that are active.\n"
555+
"In addition, the following are available as category names with special meanings:\n"
556+
" - \"all\", \"1\" : represent all logging categories.\n"
557+
" - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
558+
"\nArguments:\n"
559+
"1. \"include\" (array of strings, optional) A json array of categories to add debug logging\n"
560+
" [\n"
561+
" \"category\" (string) the valid logging category\n"
562+
" ,...\n"
563+
" ]\n"
564+
"2. \"exclude\" (array of strings, optional) A json array of categories to remove debug logging\n"
565+
" [\n"
566+
" \"category\" (string) the valid logging category\n"
567+
" ,...\n"
568+
" ]\n"
569+
"\nResult:\n"
570+
"{ (json object where keys are the logging categories, and values indicates its status\n"
571+
" \"category\": 0|1, (numeric) if being debug logged or not. 0:inactive, 1:active\n"
572+
" ...\n"
573+
"}\n"
555574
"\nExamples:\n"
556575
+ HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
557576
+ 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)