| 375 | } |
| 376 | |
| 377 | UniValue logging(const JSONRPCRequest& request) |
| 378 | { |
| 379 | if (request.fHelp || request.params.size() > 2) { |
| 380 | throw std::runtime_error( |
| 381 | "logging ( <include> <exclude> )\n" |
| 382 | "Gets and sets the logging configuration.\n" |
| 383 | "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n" |
| 384 | "When called with arguments, adds or removes categories from debug logging and return the lists above.\n" |
| 385 | "The arguments are evaluated in order \"include\", \"exclude\".\n" |
| 386 | "If an item is both included and excluded, it will thus end up being excluded.\n" |
| 387 | "The valid logging categories are: " + ListLogCategories() + "\n" |
| 388 | "In addition, the following are available as category names with special meanings:\n" |
| 389 | " - \"all\", \"1\" : represent all logging categories.\n" |
| 390 | " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" |
| 391 | "\nArguments:\n" |
| 392 | "1. \"include\" (array of strings, optional) A json array of categories to add debug logging\n" |
| 393 | " [\n" |
| 394 | " \"category\" (string) the valid logging category\n" |
| 395 | " ,...\n" |
| 396 | " ]\n" |
| 397 | "2. \"exclude\" (array of strings, optional) A json array of categories to remove debug logging\n" |
| 398 | " [\n" |
| 399 | " \"category\" (string) the valid logging category\n" |
| 400 | " ,...\n" |
| 401 | " ]\n" |
| 402 | "\nResult:\n" |
| 403 | "{ (json object where keys are the logging categories, and values indicates its status\n" |
| 404 | " \"category\": 0|1, (numeric) if being debug logged or not. 0:inactive, 1:active\n" |
| 405 | " ...\n" |
| 406 | "}\n" |
| 407 | "\nExamples:\n" |
| 408 | + HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") |
| 409 | + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"") |
| 410 | ); |
| 411 | } |
| 412 | |
| 413 | uint32_t original_log_categories = g_logger->GetCategoryMask(); |
| 414 | if (request.params[0].isArray()) { |
| 415 | EnableOrDisableLogCategories(request.params[0], true); |
| 416 | } |
| 417 | if (request.params[1].isArray()) { |
| 418 | EnableOrDisableLogCategories(request.params[1], false); |
| 419 | } |
| 420 | uint32_t updated_log_categories = g_logger->GetCategoryMask(); |
| 421 | uint32_t changed_log_categories = original_log_categories ^ updated_log_categories; |
| 422 | |
| 423 | // Update libevent logging if BCLog::LIBEVENT has changed. |
| 424 | // If the library version doesn't allow it, UpdateHTTPServerLogging() returns false, |
| 425 | // in which case we should clear the BCLog::LIBEVENT flag. |
| 426 | // Throw an error if the user has explicitly asked to change only the libevent |
| 427 | // flag and it failed. |
| 428 | if (changed_log_categories & BCLog::LIBEVENT) { |
| 429 | if (!UpdateHTTPServerLogging(g_logger->WillLogCategory(BCLog::LIBEVENT))) { |
| 430 | g_logger->DisableCategory(BCLog::LIBEVENT); |
| 431 | if (changed_log_categories == BCLog::LIBEVENT) { |
| 432 | throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1."); |
| 433 | } |
| 434 | } |
nothing calls this directly
no test coverage detected