Adds an RPC to get/set active logging categories.
First commit allows all categories except libevent to be reconfigured during runtime.
Second commit modifies InitHTTPServer()
to allow leveldb logging to be reconfigured during runtime.
Adds an RPC to get/set active logging categories.
First commit allows all categories except libevent to be reconfigured during runtime.
Second commit modifies InitHTTPServer()
to allow leveldb logging to be reconfigured during runtime.
390- if (LogAcceptCategory(BCLog::LIBEVENT)) {
391- event_enable_debug_logging(EVENT_DBG_ALL);
392- } else {
393- event_enable_debug_logging(EVENT_DBG_NONE);
394- }
395+ event_enable_debug_logging(EVENT_DBG_ALL);
Are you sure? I’ve tested this and logging is only enabled when libevent is built in debug mode:
and
I would have thought that if we’re running libevent in debug, then performance is already hosed.
If I’m wrong, I left this as a separate commit so we can leave it out if needed. The first commit forbids trying to change libevent logging during runtime and stands on its own.
leveldb: #9999 always hands a logging class to leveldb at startup, even if logging is disabled. I don’t know if that affects performance. This PR doesn’t change that behaviour.
Turns out libevent logging can be changed at runtime: https://github.com/libevent/libevent/blob/2e52bace9f9998826bd3819af328efc8d18decf9/whatsnew-2.1.txt#L269
I’ve pushed a new commit that leaves InitHTTPServer()
unchanged and uses event_enable_debug_logging()
to update logging.
574+ + HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
575+ + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")
576+ );
577+ }
578+
579+ if (request.params.size() > 0 && request.params[0].isArray()) {
604+ UniValue result(UniValue::VOBJ);
605+ std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();
606+ for (const auto& logCatActive : vLogCatActive) {
607+ result.pushKV(logCatActive.category, logCatActive.active);
608+ }
609+ result.pushKV("WARNING", "libevent logging cannot be updated when using libevent before v2.1.1.");
If you add this warning I’d suggest it be context-sensitive:
Though you could also make it an error in that case! (e.g. make UpdateHTTPServerLogging return false and then raise a JSON exception here)
I initially tried doing something like that, but it’s a bit tricky:
I’ll see if I can come up with something sensible.
I’m perfectly fine with removing this warning from this pull and doing that later. I just don’t think it should be added unconditionally.
I’ve already applied the include/excude bitmasks by this point, and we need the before/after state to know whether to throw.
Sure. if((before ^ after) & BCLog::LIBEVENT)
would work :-) Though it’s probably best to do the check inside UpdateHTTPServerLogging because there you have the previous state, the desired new state, and the libevent version information available.
we only want to raise an error if only libevent logging is changed
That’s a good point, and indeed speaks for making it a warning instead.
Pushed an updated version that hopefully addresses @laanwj’s comments. Changes:
UpdateHTTPServerLogging()
is now called by InitHTTPServer()
. This contains the #if LIBEVENT_VERSION_NUMBER >= 0x02010100
preprocessor logic to one place.UpdateHTTPServerLogging()
now removes the BCLog::LIBEVENT
bit flag if the libevent version does not support debug logging. That means that a call to the logging RPC will return the correct value for libevent (0 if libevent logging is not supported).BCLog::LIBEVENT
flag
Adds an RPC to get and set currently active logging categories.
438+ event_enable_debug_logging(EVENT_DBG_NONE);
439+ }
440+ return true;
441+#else
442+ // Can't update libevent logging if version < 02010100
443+ logCategories &= ~BCLog::LIBEVENT;
InitHTTPServer()
and the logging()
rpc).
The help message could IMHO make it clearer how to enable and disable logging. I’ve tried “logging exclude estimatefee”, “logging estimatefee false”, “logging estimatefee exclude”, and they all give a “Error parsing JSON” error.
Is it possible to toggle logging from the console?