Skip to content

Commit

Permalink
[Core] LogAcceptCategory: use uint32_t rather than sets of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Apr 1, 2020
1 parent 6879786 commit c3dc816
Show file tree
Hide file tree
Showing 43 changed files with 588 additions and 521 deletions.
4 changes: 2 additions & 2 deletions src/activemasternode.cpp
Expand Up @@ -21,7 +21,7 @@ void CActiveMasternode::ManageStatus()

if (!fMasterNode) return;

if (fDebug) LogPrintf("CActiveMasternode::ManageStatus() - Begin\n");
if (logCategories != BCLog::NONE) LogPrintf("CActiveMasternode::ManageStatus() - Begin\n");

//need correct blocks to send ping
if (!Params().IsRegTestNet() && !masternodeSync.IsBlockchainSynced()) {
Expand Down Expand Up @@ -198,8 +198,8 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
if (mnodeman.mapSeenMasternodeBroadcast.count(hash)) mnodeman.mapSeenMasternodeBroadcast[hash].lastPing = mnp;

mnp.Relay();

return true;

} else {
// Seems like we are trying to send a ping while the Masternode is not registered in the network
errorMessage = "Obfuscation Masternode List doesn't include our Masternode, shutting down Masternode pinging service! " + vin.ToString();
Expand Down
4 changes: 2 additions & 2 deletions src/addrman.cpp
Expand Up @@ -242,7 +242,7 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime)
if (nUBucket == -1)
return;

LogPrint("addrman", "Moving %s to tried\n", addr.ToString());
LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString());

// move nId to the tried tables
MakeTried(info, nId);
Expand Down Expand Up @@ -505,4 +505,4 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)

int CAddrMan::RandomInt(int nMax){
return GetRandInt(nMax);
}
}
6 changes: 3 additions & 3 deletions src/addrman.h
Expand Up @@ -436,7 +436,7 @@ class CAddrMan
}
}
if (nLost + nLostUnk > 0) {
LogPrint("addrman", "addrman lost %i new and %i tried addresses due to collisions\n", nLostUnk, nLost);
LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions\n", nLostUnk, nLost);
}

Check();
Expand Down Expand Up @@ -508,7 +508,7 @@ class CAddrMan
Check();
}
if (fRet)
LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
LogPrint(BCLog::ADDRMAN, "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
return fRet;
}

Expand All @@ -524,7 +524,7 @@ class CAddrMan
Check();
}
if (nAdd)
LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
LogPrint(BCLog::ADDRMAN, "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
return nAdd > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/consensus/zerocoin_verify.cpp
Expand Up @@ -361,7 +361,7 @@ bool UpdateZPIVSupply(const CBlock& block, CBlockIndex* pindex, bool fJustCheck)
}

for (const auto& denom : libzerocoin::zerocoinDenomList)
LogPrint("zero", "%s coins for denomination %d pubcoin %s\n", __func__, denom, pindex->mapZerocoinSupply.at(denom));
LogPrint(BCLog::LEGACYZC, "%s coins for denomination %d pubcoin %s\n", __func__, denom, pindex->mapZerocoinSupply.at(denom));

return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/denomination_functions.cpp
Expand Up @@ -155,10 +155,10 @@ void listSpends(const std::vector<CZerocoinMint>& vSelectedMints)

CAmount nTotal = 0;
for (auto& denom : libzerocoin::zerocoinDenomList) {
LogPrint("zero", "%s %d coins for denomination %d used\n", __func__, mapZerocoinSupply.at(denom), denom);
LogPrint(BCLog::LEGACYZC, "%s %d coins for denomination %d used\n", __func__, mapZerocoinSupply.at(denom), denom);
nTotal += libzerocoin::ZerocoinDenominationToAmount(denom);
}
LogPrint("zero", "Total value of coins %d\n", nTotal);
LogPrint(BCLog::LEGACYZC, "Total value of coins %d\n", nTotal);
}

// -------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -416,11 +416,11 @@ std::vector<CMintMeta> SelectMintsFromList(const CAmount nValueTarget, CAmount&
// calculate the change needed and the map of coins used
nCoinsReturned = calculateChange(nMaxNumberOfSpends, nValueTarget, mapOfDenomsHeld, mapOfDenomsUsed);
if (nCoinsReturned == 0) {
LogPrint("zero", "%s: Problem getting change (TBD) or Too many spends %d\n", __func__, nValueTarget);
LogPrint(BCLog::LEGACYZC, "%s: Problem getting change (TBD) or Too many spends %d\n", __func__, nValueTarget);
vSelectedMints.clear();
} else {
vSelectedMints = getSpends(listMints, mapOfDenomsUsed, nSelectedValue);
LogPrint("zero", "%s: %d coins in change for %d\n", __func__, nCoinsReturned, nValueTarget);
LogPrint(BCLog::LEGACYZC, "%s: %d coins in change for %d\n", __func__, nCoinsReturned, nValueTarget);
}
return vSelectedMints;
}
6 changes: 3 additions & 3 deletions src/httprpc.cpp
Expand Up @@ -169,7 +169,7 @@ static bool InitRPCAuthentication()

bool StartHTTPRPC()
{
LogPrint("rpc", "Starting HTTP RPC server\n");
LogPrint(BCLog::RPC, "Starting HTTP RPC server\n");
if (!InitRPCAuthentication())
return false;

Expand All @@ -183,12 +183,12 @@ bool StartHTTPRPC()

void InterruptHTTPRPC()
{
LogPrint("rpc", "Interrupting HTTP RPC server\n");
LogPrint(BCLog::RPC, "Interrupting HTTP RPC server\n");
}

void StopHTTPRPC()
{
LogPrint("rpc", "Stopping HTTP RPC server\n");
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
UnregisterHTTPHandler("/", true);
if (httpRPCTimerInterface) {
RPCUnsetTimerInterface(httpRPCTimerInterface);
Expand Down
34 changes: 17 additions & 17 deletions src/httpserver.cpp
Expand Up @@ -221,7 +221,7 @@ static bool InitHTTPAllowList()
std::string strAllowed;
for (const CSubNet& subnet : rpc_allow_subnets)
strAllowed += subnet.ToString() + " ";
LogPrint("http", "Allowing HTTP connections from: %s\n", strAllowed);
LogPrint(BCLog::HTTP, "Allowing HTTP connections from: %s\n", strAllowed);
return true;
}

Expand Down Expand Up @@ -251,7 +251,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
{
std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));

LogPrint("http", "Received a %s request for %s from %s\n",
LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString());

// Early address-based allow check
Expand Down Expand Up @@ -299,17 +299,17 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
/** Callback to reject HTTP requests after shutdown. */
static void http_reject_request_cb(struct evhttp_request* req, void*)
{
LogPrint("http", "Rejecting request while shutting down\n");
LogPrint(BCLog::HTTP, "Rejecting request while shutting down\n");
evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL);
}
/** Event dispatcher thread */
static bool ThreadHTTP(struct event_base* base, struct evhttp* http)
{
util::ThreadRename("bitcoin-http");
LogPrint("http", "Entering http event loop\n");
LogPrint(BCLog::HTTP, "Entering http event loop\n");
event_base_dispatch(base);
// Event loop will be interrupted by InterruptHTTPServer()
LogPrint("http", "Exited http event loop\n");
LogPrint(BCLog::HTTP, "Exited http event loop\n");
return event_base_got_break(base) == 0;
}

Expand Down Expand Up @@ -341,7 +341,7 @@ static bool HTTPBindAddresses(struct evhttp* http)

// Bind addresses
for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
LogPrint("http", "Binding RPC on address %s port %i\n", i->first, i->second);
LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second);
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? NULL : i->first.c_str(), i->second);
if (bind_handle) {
boundSockets.push_back(bind_handle);
Expand Down Expand Up @@ -369,7 +369,7 @@ static void libevent_log_cb(int severity, const char *msg)
if (severity >= EVENT_LOG_WARN) // Log warn messages and higher without debug category
LogPrintf("libevent: %s\n", msg);
else
LogPrint("libevent", "libevent: %s\n", msg);
LogPrint(BCLog::LIBEVENT, "libevent: %s\n", msg);
}

bool InitHTTPServer()
Expand All @@ -392,7 +392,7 @@ bool InitHTTPServer()
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
// If -debug=libevent, set full libevent debugging.
// Otherwise, disable all libevent debugging.
if (LogAcceptCategory("libevent"))
if (LogAcceptCategory(BCLog::LIBEVENT))
event_enable_debug_logging(EVENT_DBG_ALL);
else
event_enable_debug_logging(EVENT_DBG_NONE);
Expand Down Expand Up @@ -429,7 +429,7 @@ bool InitHTTPServer()
return false;
}

LogPrint("http", "Initialized HTTP server\n");
LogPrint(BCLog::HTTP, "Initialized HTTP server\n");
int workQueueDepth = std::max((long)GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth);

Expand All @@ -444,7 +444,7 @@ std::future<bool> threadResult;

bool StartHTTPServer()
{
LogPrint("http", "Starting HTTP server\n");
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
int rpcThreads = std::max((long)GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
std::packaged_task<bool(event_base*, evhttp*)> task(ThreadHTTP);
Expand All @@ -460,7 +460,7 @@ bool StartHTTPServer()

void InterruptHTTPServer()
{
LogPrint("http", "Interrupting HTTP server\n");
LogPrint(BCLog::HTTP, "Interrupting HTTP server\n");
if (eventHTTP) {
for (evhttp_bound_socket *socket : boundSockets) {
evhttp_del_accept_socket(eventHTTP, socket);
Expand All @@ -473,15 +473,15 @@ void InterruptHTTPServer()

void StopHTTPServer()
{
LogPrint("http", "Stopping HTTP server\n");
LogPrint(BCLog::HTTP, "Stopping HTTP server\n");
if (workQueue) {
LogPrint("http", "Waiting for HTTP worker threads to exit\n");
LogPrint(BCLog::HTTP, "Waiting for HTTP worker threads to exit\n");
workQueue->WaitExit();
delete workQueue;
}
MilliSleep(500); // Avoid race condition while the last HTTP-thread is exiting
if (eventBase) {
LogPrint("http", "Waiting for HTTP event thread to exit\n");
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
// Give event loop a few seconds to exit (to send back last RPC responses), then break it
// Before this was solved with event_base_loopexit, but that didn't work as expected in
// at least libevent 2.0.21 and always introduced a delay. In libevent
Expand All @@ -503,7 +503,7 @@ void StopHTTPServer()
event_base_free(eventBase);
eventBase = 0;
}
LogPrint("http", "Stopped HTTP server\n");
LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
}

struct event_base* EventBase()
Expand Down Expand Up @@ -650,7 +650,7 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod()

void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
{
LogPrint("http", "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
}

Expand All @@ -663,7 +663,7 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
break;
if (i != iend)
{
LogPrint("http", "Unregistering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
LogPrint(BCLog::HTTP, "Unregistering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
pathHandlers.erase(i);
}
}
25 changes: 15 additions & 10 deletions src/init.cpp
Expand Up @@ -348,7 +348,7 @@ void OnRPCStopped()
uiInterface.NotifyBlockTip.disconnect(RPCNotifyBlockChange);
//RPCNotifyBlockChange(0);
g_best_block_cv.notify_all();
LogPrint("rpc", "RPC stopped.\n");
LogPrint(BCLog::RPC, "RPC stopped.\n");
}

void OnRPCPreCommand(const CRPCCommand& cmd)
Expand Down Expand Up @@ -494,11 +494,8 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf(_("Stop running after importing blocks from disk (default: %u)"), 0));
strUsage += HelpMessageOpt("-sporkkey=<privkey>", _("Enable spork administration functionality with the appropriate private key."));
}
std::string debugCategories = "addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, tor, mempool, net, proxy, http, libevent, pivx, (obfuscation, swiftx, masternode, mnpayments, mnbudget, zero, staking)"; // Don't translate these and qt below
if (mode == HMM_BITCOIN_QT)
debugCategories += ", qt";
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
_("If <category> is not supplied, output all debugging information.") + _("<category> can be:") + " " + debugCategories + ".");
_("If <category> is not supplied, output all debugging information.") + _("<category> can be:") + " " + ListLogCategories() + ".");
if (GetBoolArg("-help-debug", false))
strUsage += HelpMessageOpt("-nodebug", "Turn off debugging messages, same as -debug=0");
#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -932,11 +929,19 @@ bool AppInit2()

// ********************************************************* Step 3: parameter-to-internal-flags

fDebug = !mapMultiArgs["-debug"].empty();
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
const std::vector<std::string>& categories = mapMultiArgs["-debug"];
if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), std::string("0")) != categories.end())
fDebug = false;

if (!(GetBoolArg("-nodebug", false) ||
find(categories.begin(), categories.end(), std::string("0")) != categories.end())) {
for (const auto& cat : categories) {
uint32_t flag;
if (!GetLogCategory(&flag, &cat)) {
UIWarning(strprintf(_("Unsupported logging category %s.\n"), cat));
}
logCategories |= flag;
}
}

// Check for -debugnet
if (GetBoolArg("-debugnet", false))
Expand Down Expand Up @@ -1043,7 +1048,7 @@ bool AppInit2()
#ifndef WIN32
CreatePidFile(GetPidFile(), getpid());
#endif
if (GetBoolArg("-shrinkdebugfile", !fDebug))
if (GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE))
ShrinkDebugFile();
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
LogPrintf("PIVX version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);
Expand Down Expand Up @@ -1537,7 +1542,7 @@ bool AppInit2()
}
}
} catch (const std::exception& e) {
if (fDebug) LogPrintf("%s\n", e.what());
LogPrintf("%s\n", e.what());
strLoadError = _("Error opening block database");
fVerifyingBlocks = false;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel.cpp
Expand Up @@ -69,7 +69,7 @@ bool CStakeKernel::CheckKernelHash(bool fSkipLog) const
const bool res = hashProofOfStake < bnTarget;

if (!fSkipLog || res) {
LogPrint("staking", "%s : Proof Of Stake:"
LogPrint(BCLog::STAKING, "%s : Proof Of Stake:"
"\nssUniqueID=%s"
"\nnTimeTx=%d"
"\nhashProofOfStake=%s"
Expand Down

0 comments on commit c3dc816

Please sign in to comment.