Skip to content

Commit

Permalink
Set BCLog::LIBEVENT correctly for old libevent versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Apr 6, 2020
1 parent cbaf724 commit ec43b51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,13 @@ bool InitHTTPServer()

// Redirect libevent's logging to our own log
event_set_log_callback(&libevent_log_cb);
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
// If -debug=libevent, set full libevent debugging.
// Otherwise, disable all libevent debugging.
if (LogAcceptCategory(BCLog::LIBEVENT))
event_enable_debug_logging(EVENT_DBG_ALL);
else
event_enable_debug_logging(EVENT_DBG_NONE);
#endif
// Update libevent's log handling. Returns false if our version of
// libevent doesn't support debug logging, in which case we should
// clear the BCLog::LIBEVENT flag.
if (!UpdateHTTPServerLogging(logCategories & BCLog::LIBEVENT)) {
logCategories &= ~BCLog::LIBEVENT;
}

#ifdef WIN32
evthread_use_windows_threads();
#else
Expand Down Expand Up @@ -439,6 +438,20 @@ bool InitHTTPServer()
return true;
}

bool UpdateHTTPServerLogging(bool enable) {
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
if (enable) {
event_enable_debug_logging(EVENT_DBG_ALL);
} else {
event_enable_debug_logging(EVENT_DBG_NONE);
}
return true;
#else
// Can't update libevent logging if version < 02010100
return false;
#endif
}

std::thread threadHTTP;
std::future<bool> threadResult;

Expand Down
4 changes: 4 additions & 0 deletions src/httpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ void InterruptHTTPServer();
/** Stop HTTP server */
void StopHTTPServer();

/** Change logging level for libevent. Removes BCLog::LIBEVENT from logCategories if
* libevent doesn't support debug logging.*/
bool UpdateHTTPServerLogging(bool enable);

/** Handler for requests to a certain HTTP path */
typedef std::function<void(HTTPRequest* req, const std::string &)> HTTPRequestHandler;
/** Register handler for prefix.
Expand Down

0 comments on commit ec43b51

Please sign in to comment.