Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
Show First 20 Lines • Show All 403 Lines • ▼ Show 20 Lines | |||||
static void EnableOrDisableLogCategories(UniValue cats, bool enable) { | static void EnableOrDisableLogCategories(UniValue cats, bool enable) { | ||||
cats = cats.get_array(); | cats = cats.get_array(); | ||||
for (size_t i = 0; i < cats.size(); ++i) { | for (size_t i = 0; i < cats.size(); ++i) { | ||||
std::string cat = cats[i].get_str(); | std::string cat = cats[i].get_str(); | ||||
bool success; | bool success; | ||||
if (enable) { | if (enable) { | ||||
success = GetLogger().EnableCategory(cat); | success = LogInstance().EnableCategory(cat); | ||||
} else { | } else { | ||||
success = GetLogger().DisableCategory(cat); | success = LogInstance().DisableCategory(cat); | ||||
} | } | ||||
if (!success) { | if (!success) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"unknown logging category " + cat); | "unknown logging category " + cat); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Show All 38 Lines | if (request.fHelp || request.params.size() > 2) { | ||||
"0:inactive, 1:active\n" | "0:inactive, 1:active\n" | ||||
" ...\n" | " ...\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + | HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + | ||||
HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")); | HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")); | ||||
} | } | ||||
uint32_t original_log_categories = GetLogger().GetCategoryMask(); | uint32_t original_log_categories = LogInstance().GetCategoryMask(); | ||||
if (request.params[0].isArray()) { | if (request.params[0].isArray()) { | ||||
EnableOrDisableLogCategories(request.params[0], true); | EnableOrDisableLogCategories(request.params[0], true); | ||||
} | } | ||||
if (request.params[1].isArray()) { | if (request.params[1].isArray()) { | ||||
EnableOrDisableLogCategories(request.params[1], false); | EnableOrDisableLogCategories(request.params[1], false); | ||||
} | } | ||||
uint32_t updated_log_categories = GetLogger().GetCategoryMask(); | uint32_t updated_log_categories = LogInstance().GetCategoryMask(); | ||||
uint32_t changed_log_categories = | uint32_t changed_log_categories = | ||||
original_log_categories ^ updated_log_categories; | original_log_categories ^ updated_log_categories; | ||||
/** | /** | ||||
* Update libevent logging if BCLog::LIBEVENT has changed. | * Update libevent logging if BCLog::LIBEVENT has changed. | ||||
* If the library version doesn't allow it, UpdateHTTPServerLogging() | * If the library version doesn't allow it, UpdateHTTPServerLogging() | ||||
* returns false, in which case we should clear the BCLog::LIBEVENT flag. | * returns false, in which case we should clear the BCLog::LIBEVENT flag. | ||||
* Throw an error if the user has explicitly asked to change only the | * Throw an error if the user has explicitly asked to change only the | ||||
* libevent flag and it failed. | * libevent flag and it failed. | ||||
*/ | */ | ||||
if (changed_log_categories & BCLog::LIBEVENT) { | if (changed_log_categories & BCLog::LIBEVENT) { | ||||
if (!UpdateHTTPServerLogging( | if (!UpdateHTTPServerLogging( | ||||
GetLogger().WillLogCategory(BCLog::LIBEVENT))) { | LogInstance().WillLogCategory(BCLog::LIBEVENT))) { | ||||
GetLogger().DisableCategory(BCLog::LIBEVENT); | LogInstance().DisableCategory(BCLog::LIBEVENT); | ||||
if (changed_log_categories == BCLog::LIBEVENT) { | if (changed_log_categories == BCLog::LIBEVENT) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"libevent logging cannot be updated when " | "libevent logging cannot be updated when " | ||||
"using libevent before v2.1.1."); | "using libevent before v2.1.1."); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |