Skip to content

Instantly share code, notes, and snippets.

@willcl-ark
Created June 28, 2023 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willcl-ark/cb90438c412b55c2db22d86e5e4b316d to your computer and use it in GitHub Desktop.
Save willcl-ark/cb90438c412b55c2db22d86e5e4b316d to your computer and use it in GitHub Desktop.
bitcoin core log patch
commit 39e9f43014e9aa9383cc792015e91774fa5b792b
Author: willcl-ark <will@256k1.dev>
Date: Thu Jun 15 09:08:05 2023 +0100
RPC: add 'log' rpc to set single
diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp
index 3828401642..4f1986695b 100644
--- a/src/rpc/node.cpp
+++ b/src/rpc/node.cpp
@@ -204,6 +204,57 @@ static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
}
}
+static RPCHelpMan log()
+{
+ return RPCHelpMan{"log",
+ "Set a single log category.\n"
+ "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
+ "When called with arguments, adds or removes the category from debug logging and returns the log category status.\n"
+ "The valid logging categories are: " + LogInstance().LogCategoriesString() + "\n"
+ ,
+ {
+ {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "The command to enable or disable logging categories (either 'enable' or 'disable')"},
+ {"category", RPCArg::Type::STR, RPCArg::Optional::NO, "The log category to modify"},
+ },
+ RPCResult{
+ RPCResult::Type::OBJ_DYN, "", "keys are the logging categories, and values indicates its status",
+ {
+ {RPCResult::Type::BOOL, "category", "if being debug logged or not. false:inactive, true:active"},
+ }
+ },
+ RPCExamples{
+ HelpExampleCli("log", "enable net")
+ + HelpExampleRpc("log", "disable mempool")
+ },
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
+{
+ std::string command = request.params[0].get_str();
+ std::string category = request.params[1].get_str();
+
+ if (command == "enable") {
+ LogInstance().EnableCategory(category);
+ } else if (command == "disable") {
+ LogInstance().DisableCategory(category);
+ } else {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid command. Available commands are 'enable' or 'disable'.");
+ }
+ //
+ // Update libevent logging if BCLog::LIBEVENT has changed.
+ if (category == "libevent") {
+ UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT));
+ }
+
+ UniValue result(UniValue::VOBJ);
+ for (const auto& logCatActive : LogInstance().LogCategoriesList()) {
+ result.pushKV(logCatActive.category, logCatActive.active);
+ }
+
+ return result;
+},
+ };
+}
+
+
static RPCHelpMan logging()
{
return RPCHelpMan{"logging",
@@ -406,6 +457,7 @@ void RegisterNodeRPCCommands(CRPCTable& t)
{"hidden", &echo},
{"hidden", &echojson},
{"hidden", &echoipc},
+ {"hidden", &log},
};
for (const auto& c : commands) {
t.appendCommand(c.name, &c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment