aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/misc.cpp
diff options
context:
space:
mode:
authorJim Posen <jimpo@coinbase.com>2018-04-11 13:02:01 -0700
committerJim Posen <jimpo@coinbase.com>2018-04-27 16:10:02 -0700
commit3316a9ebb66171937efddb213daed64fe51c4082 (patch)
treed70ee40dd461cb472fab97e13c4af86dc3180a9e /src/rpc/misc.cpp
parent6a6d764ca5616e5d1f1848b0010613c49bd38e61 (diff)
util: Encapsulate logCategories within BCLog::Logger.
Diffstat (limited to 'src/rpc/misc.cpp')
-rw-r--r--src/rpc/misc.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
index 6754407dbd..26bf21356e 100644
--- a/src/rpc/misc.cpp
+++ b/src/rpc/misc.cpp
@@ -346,9 +346,8 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
}
}
-uint32_t getCategoryMask(UniValue cats) {
+void EnableOrDisableLogCategories(UniValue cats, bool enable) {
cats = cats.get_array();
- uint32_t mask = 0;
for (unsigned int i = 0; i < cats.size(); ++i) {
uint32_t flag = 0;
std::string cat = cats[i].get_str();
@@ -356,11 +355,14 @@ uint32_t getCategoryMask(UniValue cats) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown logging category " + cat);
}
if (flag == BCLog::NONE) {
- return 0;
+ return;
+ }
+ if (enable) {
+ g_logger->EnableCategory(static_cast<BCLog::LogFlags>(flag));
+ } else {
+ g_logger->DisableCategory(static_cast<BCLog::LogFlags>(flag));
}
- mask |= flag;
}
- return mask;
}
UniValue logging(const JSONRPCRequest& request)
@@ -399,25 +401,25 @@ UniValue logging(const JSONRPCRequest& request)
);
}
- uint32_t originalLogCategories = logCategories;
+ uint32_t original_log_categories = g_logger->GetCategoryMask();
if (request.params[0].isArray()) {
- logCategories |= getCategoryMask(request.params[0]);
+ EnableOrDisableLogCategories(request.params[0], true);
}
-
if (request.params[1].isArray()) {
- logCategories &= ~getCategoryMask(request.params[1]);
+ EnableOrDisableLogCategories(request.params[1], false);
}
+ uint32_t updated_log_categories = g_logger->GetCategoryMask();
+ uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
// Update libevent logging if BCLog::LIBEVENT has changed.
// If the library version doesn't allow it, UpdateHTTPServerLogging() 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 libevent
// flag and it failed.
- uint32_t changedLogCategories = originalLogCategories ^ logCategories;
- if (changedLogCategories & BCLog::LIBEVENT) {
- if (!UpdateHTTPServerLogging(logCategories & BCLog::LIBEVENT)) {
- logCategories &= ~BCLog::LIBEVENT;
- if (changedLogCategories == BCLog::LIBEVENT) {
+ if (changed_log_categories & BCLog::LIBEVENT) {
+ if (!UpdateHTTPServerLogging(g_logger->WillLogCategory(BCLog::LIBEVENT))) {
+ g_logger->DisableCategory(BCLog::LIBEVENT);
+ if (changed_log_categories == BCLog::LIBEVENT) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1.");
}
}