Skip to content

Commit 4d9950d

Browse files
committed
Set BCLog::LIBEVENT correctly for old libevent versions.
1 parent e19586a commit 4d9950d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/httpserver.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,13 @@ bool InitHTTPServer()
384384

385385
// Redirect libevent's logging to our own log
386386
event_set_log_callback(&libevent_log_cb);
387-
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
388-
// If -debug=libevent, set full libevent debugging.
389-
// Otherwise, disable all libevent debugging.
390-
if (LogAcceptCategory(BCLog::LIBEVENT)) {
391-
event_enable_debug_logging(EVENT_DBG_ALL);
392-
} else {
393-
event_enable_debug_logging(EVENT_DBG_NONE);
387+
// Update libevent's log handling. Returns false if our version of
388+
// libevent doesn't support debug logging, in which case we should
389+
// clear the BCLog::LIBEVENT flag.
390+
if (!UpdateHTTPServerLogging(logCategories & BCLog::LIBEVENT)) {
391+
logCategories &= ~BCLog::LIBEVENT;
394392
}
395-
#endif
393+
396394
#ifdef WIN32
397395
evthread_use_windows_threads();
398396
#else
@@ -435,6 +433,20 @@ bool InitHTTPServer()
435433
return true;
436434
}
437435

436+
bool UpdateHTTPServerLogging(bool enable) {
437+
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
438+
if (enable) {
439+
event_enable_debug_logging(EVENT_DBG_ALL);
440+
} else {
441+
event_enable_debug_logging(EVENT_DBG_NONE);
442+
}
443+
return true;
444+
#else
445+
// Can't update libevent logging if version < 02010100
446+
return false;
447+
#endif
448+
}
449+
438450
std::thread threadHTTP;
439451
std::future<bool> threadResult;
440452

src/httpserver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ void InterruptHTTPServer();
3232
/** Stop HTTP server */
3333
void StopHTTPServer();
3434

35+
/** Change logging level for libevent. Removes BCLog::LIBEVENT from logCategories if
36+
* libevent doesn't support debug logging.*/
37+
bool UpdateHTTPServerLogging(bool enable);
38+
3539
/** Handler for requests to a certain HTTP path */
3640
typedef std::function<bool(HTTPRequest* req, const std::string &)> HTTPRequestHandler;
3741
/** Register handler for prefix.

0 commit comments

Comments
 (0)