Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fDebug3,4, and net and convert to BCLog::LogFlags #1663

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ std::string HelpMessage()
#endif
strUsage +=
" -testnet " + _("Use the test network") + "\n" +
" -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n" +
" -debugnet " + _("Output extra network debugging information") + "\n" +
" -debug " + _("Output extra debugging information.") + "\n" +
" -logtimestamps " + _("Prepend debug output with timestamp") + "\n" +
" -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n" +
" -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n" +
Expand Down Expand Up @@ -605,15 +604,17 @@ bool AppInit2(ThreadHandlerPtr threads)

fDebug=false;

if (fDebug)
fDebugNet = true;
else
fDebugNet = GetBoolArg("-debugnet");

jamescowens marked this conversation as resolved.
Show resolved Hide resolved
if (GetArg("-debug", "false")=="true")
{
fDebug = true;
LogPrintf("Entering debug mode.");

// For now if debug is set, turn on the following categories as well.
// When the logs get fully converted over to categories, we will change
// this to a default set of enabled categories that are turned on/off
// when debug is set/unset, and the debug will be the only debug control
// flag left.
LogInstance().EnableCategory(BCLog::LogFlags::NET);
}

fDebug2 = false;
Expand All @@ -624,20 +625,6 @@ bool AppInit2(ThreadHandlerPtr threads)
LogPrintf("Entering GRC debug mode 2.");
}

fDebug3 = false;

if (GetArg("-debug3", "false")=="true")
{
fDebug3 = true;
LogPrintf("Entering GRC debug mode 3.");
}

if (GetArg("-debug4", "false")=="true")
{
fDebug4 = true;
LogPrintf("Entering RPC time debug mode");
}

fDebug10= (GetArg("-debug10","false")=="true");

#if defined(WIN32)
Expand Down Expand Up @@ -1137,7 +1124,7 @@ bool AppInit2(ThreadHandlerPtr threads)
uiInterface.InitMessage(_("Loading Persisted Data Cache..."));
//
std::string sOut = "";
if (fDebug3) LogPrintf("Loading admin Messages");
LogPrint(BCLog::LogFlags::NET, "Loading admin Messages");
LoadAdminMessages(true,sOut);
LogPrintf("Done loading Admin messages");

Expand All @@ -1164,7 +1151,7 @@ bool AppInit2(ThreadHandlerPtr threads)

if (pindexBest->nVersion <= 10) {
uiInterface.InitMessage(_("Loading Network Averages..."));
if (fDebug3) LogPrintf("Loading network averages");
LogPrint(BCLog::LogFlags::NET, "Loading network averages");
jamescowens marked this conversation as resolved.
Show resolved Hide resolved

NN::Tally::LegacyRecount(NN::Tally::FindLegacyTrigger(pindexBest));
}
Expand Down
22 changes: 11 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4542,7 +4542,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (pfrom->nStartingHeight < 1 && pfrom->nServices == 0 )
{
pfrom->Misbehaving(100);
if (fDebug3) LogPrintf("Disconnecting possible hacker node with no services. Banned for 24 hours.");
LogPrint(BCLog::LogFlags::NET, "Disconnecting possible hacker node with no services. Banned for 24 hours.");
pfrom->fDisconnect=true;
return false;
}
Expand All @@ -4559,7 +4559,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// Disconnect if we connected to ourself
if (nNonce == nLocalHostNonce && nNonce > 1)
{
if (fDebug3) LogPrintf("connected to self at %s, disconnecting", pfrom->addr.ToString());
LogPrint(BCLog::LogFlags::NET, "connected to self at %s, disconnecting", pfrom->addr.ToString());
pfrom->fDisconnect = true;
return true;
}
Expand Down Expand Up @@ -4627,7 +4627,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
{
nAskedForBlocks++;
pfrom->PushGetBlocks(pindexBest, uint256(), true);
if (fDebug3) LogPrintf("Asked For blocks.");
LogPrint(BCLog::LogFlags::NET, "Asked For blocks.");
}

// Relay alerts
Expand Down Expand Up @@ -4806,19 +4806,19 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return error("message getdata size() = %" PRIszu "", vInv.size());
}

if (fDebugNet || (vInv.size() != 1))
if (vInv.size() != 1)
{
if (fDebug10) LogPrintf("received getdata (%" PRIszu " invsz)", vInv.size());
LogPrint(BCLog::LogFlags::NET, "received getdata (%" PRIszu " invsz)", vInv.size());
}

LOCK(cs_main);
for (auto const& inv : vInv)
{
if (fShutdown)
return true;
if (fDebugNet || (vInv.size() == 1))
if (vInv.size() == 1)
{
if (fDebug10) LogPrintf("received getdata for: %s", inv.ToString());
LogPrint(BCLog::LogFlags::NET, "received getdata for: %s", inv.ToString());
}

if (inv.type == MSG_BLOCK)
Expand Down Expand Up @@ -4925,12 +4925,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pindex = pindex->pnext;
int nLimit = 500;

if (fDebug3) LogPrintf("getblocks %d to %s limit %d", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20), nLimit);
LogPrint(BCLog::LogFlags::NET, "getblocks %d to %s limit %d", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20), nLimit);
for (; pindex; pindex = pindex->pnext)
{
if (pindex->GetBlockHash() == hashStop)
{
if (fDebug3) LogPrintf("getblocks stopping at %d %s", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20));
LogPrint(BCLog::LogFlags::NET, "getblocks stopping at %d %s", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20));
// ppcoin: tell downloading node about the latest block if it's
// without risk being rejected due to stake connection check
if (hashStop != hashBestChain && pindex->GetBlockTime() + nStakeMinAge > pindexBest->GetBlockTime())
Expand All @@ -4942,7 +4942,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
{
// When this block is requested, we'll send an inv that'll make them
// getblocks the next batch of inventory.
if (fDebug3) LogPrintf("getblocks stopping at limit %d %s", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20));
LogPrint(BCLog::LogFlags::NET, "getblocks stopping at limit %d %s", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20));
pfrom->hashContinue = pindex->GetBlockHash();
break;
}
Expand Down Expand Up @@ -5575,7 +5575,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)

if ( iaaf!=mapAlreadyAskedFor.end() && !fAlreadyHave )
{
if (fDebugNet) LogPrintf("sending getdata: %s", inv.ToString());
LogPrint(BCLog::LogFlags::NET, "sending getdata: %s", inv.ToString());
vGetData.push_back(inv);
if (vGetData.size() >= 1000)
{
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ bool RecvLine2(SOCKET hSocket, string& strLine)
{
// socket error
int nErr = WSAGetLastError();
if (fDebug3) LogPrintf("recv socket err: %d", nErr);
LogPrint(BCLog::LogFlags::NET, "recv socket err: %d", nErr);
return false;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ class CNode
// We're using mapAskFor as a priority queue,
// the key is the earliest time the request can be sent
int64_t& nRequestTime = mapAlreadyAskedFor[inv];
if (fDebugNet)
LogPrintf("askfor %s %" PRId64 " (%s)", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000));
LogPrint(BCLog::LogFlags::NET, "askfor %s %" PRId64 " (%s)", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000));

// Make sure not to reuse time indexes to keep things in the same order
int64_t nNow = (GetAdjustedTime() - 1) * 1000000;
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,8 +1588,8 @@ void BitcoinGUI::updateScraperIcon(int scraperEventtype, int status)
qsExcludedProjects = tr("none");
}

// If fDebug3 then show scrapers in tooltip...
if (fDebug3)
// If scraper logging category is turned on then show scrapers in tooltip...
if (LogInstance().WillLogCategory(BCLog::LogFlags::SCRAPER))
{
bDisplayScrapers = true;

Expand Down
58 changes: 1 addition & 57 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fP

result.pushKV("claim", ClaimToJson(block.GetClaim(), blockindex));

if (fDebug3) result.pushKV("BoincHash",block.vtx[0].hashBoinc);
if (LogInstance().WillLogCategory(BCLog::LogFlags::NET)) result.pushKV("BoincHash",block.vtx[0].hashBoinc);

if (fPrintTransactionDetail && blockindex->nIsSuperBlock == 1) {
result.pushKV("superblock", SuperblockToJson(block.GetSuperblock()));
Expand Down Expand Up @@ -1253,62 +1253,6 @@ UniValue debug2(const UniValue& params, bool fHelp)
return res;
}

UniValue debug3(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"debug3 <bool>\n"
"\n"
"<bool> -> Specify true or false\n"
"\n"
"Enable or disable debug mode on the fly\n");

UniValue res(UniValue::VOBJ);

fDebug3 = params[0].get_bool();

res.pushKV("Debug3", fDebug3 ? "Entering debug mode." : "Exiting debug mode.");

return res;
}

UniValue debug4(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"debug4 <bool>\n"
"\n"
"<bool> -> Specify true or false\n"
"\n"
"Enable or disable debug mode on the fly\n");

UniValue res(UniValue::VOBJ);

fDebug4 = params[0].get_bool();

res.pushKV("Debug4", fDebug4 ? "Entering debug mode." : "Exiting debug mode.");

return res;
}
UniValue debugnet(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"debugnet <bool>\n"
"\n"
"<bool> -> Specify true or false\n"
"\n"
"Enable or disable debug mode on the fly\n");

UniValue res(UniValue::VOBJ);

fDebugNet = params[0].get_bool();

res.pushKV("DebugNet", fDebugNet ? "Entering debug mode." : "Exiting debug mode.");

return res;
}

UniValue getlistof(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
Expand Down
3 changes: 0 additions & 3 deletions src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "debug" , 0 },
{ "debug10" , 0 },
{ "debug2" , 0 },
{ "debug3" , 0 },
{ "debug4" , 0 },
{ "debugnet" , 0 },
{ "getblockstats" , 0 },
{ "getblockstats" , 1 },
{ "getblockstats" , 2 },
Expand Down
10 changes: 4 additions & 6 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ static const CRPCCommand vRPCCommands[] =
{ "debug", &debug, cat_developer },
{ "debug10", &debug10, cat_developer },
{ "debug2", &debug2, cat_developer },
{ "debug3", &debug3, cat_developer },
{ "debug4", &debug4, cat_developer },
{ "debugnet", &debugnet, cat_developer },
{ "exportstats1", &rpc_exportstats, cat_developer },
{ "getblockstats", &rpc_getblockstats, cat_developer },
{ "getlistof", &getlistof, cat_developer },
Expand Down Expand Up @@ -862,13 +859,14 @@ UniValue CRPCTable::execute(const std::string& strMethod, const UniValue& params
if (!pcmd)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");

// Lets add a optional debug4 to display how long it takes the rpc commands to be performed in ms
// We will do this only on successful calls not exceptions
// Lets add a optional display if BCLog::LogFlags::RPC is set to show how long it takes
// the rpc commands to be performed in milliseconds. We will do this only on successful
// calls not exceptions.
try
{
UniValue result(UniValue::VSTR);

if (fDebug4)
if (LogInstance().WillLogCategory(BCLog::LogFlags::RPC))
{
int64_t nRPCtimebegin;
int64_t nRPCtimetotal;
Expand Down
3 changes: 0 additions & 3 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ extern UniValue currentcontractaverage(const UniValue& params, bool fHelp);
extern UniValue debug(const UniValue& params, bool fHelp);
extern UniValue debug10(const UniValue& params, bool fHelp);
extern UniValue debug2(const UniValue& params, bool fHelp);
extern UniValue debug3(const UniValue& params, bool fHelp);
extern UniValue debug4(const UniValue& params, bool fHelp);
extern UniValue debugnet(const UniValue& params, bool fHelp);
extern UniValue rpc_getblockstats(const UniValue& params, bool fHelp);
extern UniValue getlistof(const UniValue& params, bool fHelp);
extern UniValue listdata(const UniValue& params, bool fHelp);
Expand Down
11 changes: 5 additions & 6 deletions src/scraper/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void Http::Download(
const std::string &userpass)
{
ScopedFile fp(fsbridge::fopen(destination, "wb"), &fclose);
if(!fp)
if (!fp)
throw std::runtime_error(
tfm::format("Error opening target %s: %s (%d)", destination, strerror(errno), errno));

Expand Down Expand Up @@ -206,18 +206,17 @@ std::string Http::GetEtag(
// Find ETag header.
std::string etag;

if(fDebug3) _log(logattribute::INFO, "Http::ETag", "Header: \n" + header);
_log(logattribute::INFO, "Http::ETag", "Header: \n" + header);

std::istringstream iss(header);
for (std::string line; std::getline(iss, line);)
{
if(size_t pos = line.find("ETag: ") != std::string::npos)
if (size_t pos = line.find("ETag: ") != std::string::npos)
{
etag = line.substr(pos+6, line.size());
etag = etag.substr(1, etag.size() - 3);

if (fDebug)
_log(logattribute::INFO, "curl_http_header", "Captured ETag for project url <urlfile=" + url + ", ETag=" + etag + ">");
_log(logattribute::INFO, "curl_http_header", "Captured ETag for project url <urlfile=" + url + ", ETag=" + etag + ">");

return etag;
}
Expand Down Expand Up @@ -270,7 +269,7 @@ void Http::DownloadSnapshot()

ScopedFile fp(fsbridge::fopen(destination, "wb"), &fclose);

if(!fp)
if (!fp)
{
DownloadStatus.SnapshotDownloadFailed = true;

Expand Down
Loading