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);
Don't do this! This existed for a reason. What you did will reduce libevent performance extremely by always enabling their internal debugging. Same is probably true for leveldb. I'd prefer just not to allow to switch those at runtime. (unless it can be done in a thread-safe way later on, but I don't think so)
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.
Yes, it is possible to compile libevent wholesale without debug messages. However, most distributions enable them. Even if it is compiled with debug messages, normally they just sink at the libevent side before even being formatted: https://github.com/libevent/libevent/blob/master/log-internal.h#L80 Remember that libevent debugging is extremely noisy. It always is - the mask is currently unused - there are no specific flags. There will be significant overhead to dropping the messages at our side, after formatting. That's worth it for the questionable advantage of being able to enable it during runtime.
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.
Concept ACK ofcourse
Oh. That's great. Concept ACK. Will test soon.
Pushed a new commit that I hope addresses @laanwj's point here: #10150 (review)
574 | + + HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") 575 | + + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"") 576 | + ); 577 | + } 578 | + 579 | + if (request.params.size() > 0 && request.params[0].isArray()) {
It looks like this code is almost duplicated with the exclude case (except the |/& and true/false). Might make sense to roll this into a function that converts a list of flag strings into a bitmask and apply that wholesale.
sounds sensible. Done
Yup, thanks, much better
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;
Looks good to me. One nit: I don't think this global flag should be changed here as a side-effect. Maybe move the "disable the flag in logCategories if this function returns false" logic outside the function.
ok, changed so that the caller updates the logCategories bitfield (happens in two places - InitHTTPServer() and the logging() rpc).
Tested ACK 7fd50c3
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?