@@ -555,6 +555,59 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
555
555
}
556
556
}
557
557
558
+ uint32_t getCategoryMask (UniValue cats) {
559
+ cats = cats.get_array ();
560
+ uint32_t mask = 0 ;
561
+ for (unsigned int i = 0 ; i < cats.size (); ++i) {
562
+ uint32_t flag = 0 ;
563
+ std::string cat = cats[i].get_str ();
564
+ if (!GetLogCategory (&flag, &cat)) {
565
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " unknown logging category " + cat);
566
+ }
567
+ mask |= flag;
568
+ }
569
+ return mask;
570
+ }
571
+
572
+ UniValue logging (const JSONRPCRequest& request)
573
+ {
574
+ if (request.fHelp || request.params .size () > 2 ) {
575
+ throw std::runtime_error (
576
+ " logging [include,...] <exclude>\n "
577
+ " Gets and sets the logging configuration.\n "
578
+ " When called without an argument, returns the list of categories that are currently being debug logged.\n "
579
+ " When called with arguments, adds or removes categories from debug logging.\n "
580
+ " The valid logging categories are: " + ListLogCategories () + " \n "
581
+ " libevent logging is configured on startup and cannot be modified by this RPC during runtime."
582
+ " Arguments:\n "
583
+ " 1. \" include\" (array of strings) add debug logging for these categories.\n "
584
+ " 2. \" exclude\" (array of strings) remove debug logging for these categories.\n "
585
+ " \n Result: <categories> (string): a list of the logging categories that are active.\n "
586
+ " \n Examples:\n "
587
+ + HelpExampleCli (" logging" , " \" [\\\" all\\\" ]\" \" [\\\" http\\\" ]\" " )
588
+ + HelpExampleRpc (" logging" , " [\" all\" ], \" [libevent]\" " )
589
+ );
590
+ }
591
+
592
+ uint32_t originalLogCategories = logCategories;
593
+ if (request.params .size () > 0 && request.params [0 ].isArray ()) {
594
+ logCategories |= getCategoryMask (request.params [0 ]);
595
+ }
596
+
597
+ if (request.params .size () > 1 && request.params [1 ].isArray ()) {
598
+ logCategories &= ~getCategoryMask (request.params[1 ]);
599
+ }
600
+
601
+
602
+ UniValue result (UniValue::VOBJ);
603
+ std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories ();
604
+ for (const auto & logCatActive : vLogCatActive) {
605
+ result.pushKV (logCatActive.category , logCatActive.active );
606
+ }
607
+
608
+ return result;
609
+ }
610
+
558
611
UniValue echo (const JSONRPCRequest& request)
559
612
{
560
613
if (request.fHelp )
@@ -581,7 +634,8 @@ static const CRPCCommand commands[] =
581
634
/* Not shown in help */
582
635
{ " hidden" , " setmocktime" , &setmocktime, true , {" timestamp" }},
583
636
{ " hidden" , " echo" , &echo, true , {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
584
- { " hidden" , " echojson" , &echo, true , {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
637
+ { " hidden" , " echojson" , &echo, true , {" arg0" ," arg1" ," arg2" ," arg3" ," arg4" ," arg5" ," arg6" ," arg7" ," arg8" ," arg9" }},
638
+ { " hidden" , " logging" , &logging, true , {" include" , " exclude" }},
585
639
};
586
640
587
641
void RegisterMiscRPCCommands (CRPCTable &t)
0 commit comments