@@ -346,21 +346,23 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
346346 }
347347}
348348
349- uint32_t getCategoryMask (UniValue cats) {
349+ void EnableOrDisableLogCategories (UniValue cats, bool enable ) {
350350 cats = cats.get_array ();
351- uint32_t mask = 0 ;
352351 for (unsigned int i = 0 ; i < cats.size (); ++i) {
353352 uint32_t flag = 0 ;
354353 std::string cat = cats[i].get_str ();
355354 if (!GetLogCategory (&flag, &cat)) {
356355 throw JSONRPCError (RPC_INVALID_PARAMETER, " unknown logging category " + cat);
357356 }
358357 if (flag == BCLog::NONE) {
359- return 0 ;
358+ return ;
359+ }
360+ if (enable) {
361+ g_logger->EnableCategory (static_cast <BCLog::LogFlags>(flag));
362+ } else {
363+ g_logger->DisableCategory (static_cast <BCLog::LogFlags>(flag));
360364 }
361- mask |= flag;
362365 }
363- return mask;
364366}
365367
366368UniValue logging (const JSONRPCRequest& request)
@@ -399,25 +401,25 @@ UniValue logging(const JSONRPCRequest& request)
399401 );
400402 }
401403
402- uint32_t originalLogCategories = logCategories ;
404+ uint32_t original_log_categories = g_logger-> GetCategoryMask () ;
403405 if (request.params [0 ].isArray ()) {
404- logCategories |= getCategoryMask (request.params [0 ]);
406+ EnableOrDisableLogCategories (request.params [0 ], true );
405407 }
406-
407408 if (request.params [1 ].isArray ()) {
408- logCategories &= ~getCategoryMask (request.params[1 ]);
409+ EnableOrDisableLogCategories (request.params [1 ], false );
409410 }
411+ uint32_t updated_log_categories = g_logger->GetCategoryMask ();
412+ uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
410413
411414 // Update libevent logging if BCLog::LIBEVENT has changed.
412415 // If the library version doesn't allow it, UpdateHTTPServerLogging() returns false,
413416 // in which case we should clear the BCLog::LIBEVENT flag.
414417 // Throw an error if the user has explicitly asked to change only the libevent
415418 // flag and it failed.
416- uint32_t changedLogCategories = originalLogCategories ^ logCategories;
417- if (changedLogCategories & BCLog::LIBEVENT) {
418- if (!UpdateHTTPServerLogging (logCategories & BCLog::LIBEVENT)) {
419- logCategories &= ~BCLog::LIBEVENT;
420- if (changedLogCategories == BCLog::LIBEVENT) {
419+ if (changed_log_categories & BCLog::LIBEVENT) {
420+ if (!UpdateHTTPServerLogging (g_logger->WillLogCategory (BCLog::LIBEVENT))) {
421+ g_logger->DisableCategory (BCLog::LIBEVENT);
422+ if (changed_log_categories == BCLog::LIBEVENT) {
421423 throw JSONRPCError (RPC_INVALID_PARAMETER, " libevent logging cannot be updated when using libevent before v2.1.1." );
422424 }
423425 }
0 commit comments