Skip to content

Commit

Permalink
Merge pull request #1699 from jamescowens/finishloggingconversion
Browse files Browse the repository at this point in the history
Finish the conversion to the BCLog class based logger
  • Loading branch information
jamescowens authored Jun 1, 2020
2 parents a452e3c + 1bba908 commit bea8bc6
Show file tree
Hide file tree
Showing 31 changed files with 323 additions and 348 deletions.
2 changes: 1 addition & 1 deletion src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void CAddrMan::Good_(const CService &addr, int64_t nTime)
// TODO: maybe re-add the node, but for now, just bail out
if (nUBucket == -1) return;

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

// move nId to the tried tables
MakeTried(info, nId, nUBucket);
Expand Down
6 changes: 3 additions & 3 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class CAddrMan
LOCK(cs);
int err;
if ((err=Check_()))
LogPrint("addrman", "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err);
LogPrint(BCLog::LogFlags::ADDRMAN, "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err);
}
#endif
}
Expand All @@ -419,7 +419,7 @@ class CAddrMan
Check();
}
if (fRet)
LogPrint("addrman","Added %s from %s: %i tried, %i new", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
LogPrint(BCLog::LogFlags::ADDRMAN,"Added %s from %s: %i tried, %i new", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
return fRet;
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ bool CAlert::ProcessAlert(bool fThread)
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
LogPrint("alert", "cancelling alert %d", alert.nID);
LogPrint(BCLog::LogFlags::ALERT, "cancelling alert %d", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
LogPrint("alert", "expiring alert %d", alert.nID);
LogPrint(BCLog::LogFlags::ALERT, "expiring alert %d", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
Expand All @@ -233,7 +233,7 @@ bool CAlert::ProcessAlert(bool fThread)
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
LogPrint("alert", "alert already cancelled by %d", alert.nID);
LogPrint(BCLog::LogFlags::ALERT, "alert already cancelled by %d", alert.nID);
return false;
}
}
Expand Down Expand Up @@ -271,6 +271,6 @@ bool CAlert::ProcessAlert(bool fThread)
}
}

LogPrint("alert", "accepted alert %d, AppliesToMe()=%d", nID, AppliesToMe());
LogPrint(BCLog::LogFlags::ALERT, "accepted alert %d, AppliesToMe()=%d", nID, AppliesToMe());
return true;
}
6 changes: 3 additions & 3 deletions src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
SetBannedSetDirty(false); // no need to write down, just read data
SweepBanned(); // sweep out unused entries

LogPrint("network", "Loaded %d banned node ips/subnets from banlist.dat %dms\n",
LogPrint(BCLog::LogFlags::NET, "Loaded %d banned node ips/subnets from banlist.dat %dms\n",
banmap.size(), GetTimeMillis() - n_start);
} else {
LogPrintf("Invalid or missing banlist.dat; recreating\n");
Expand Down Expand Up @@ -51,7 +51,7 @@ void BanMan::DumpBanlist()
SetBannedSetDirty(false);
}

LogPrint("network", "Flushed %d banned node ips/subnets to banlist.dat %dms\n",
LogPrint(BCLog::LogFlags::NET, "Flushed %d banned node ips/subnets to banlist.dat %dms\n",
banmap.size(), GetTimeMillis() - n_start);
}

Expand Down Expand Up @@ -208,7 +208,7 @@ void BanMan::SweepBanned()

m_is_dirty = true;
notify_ui = true;
LogPrint("net", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString());
LogPrint(BCLog::LogFlags::NET, "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString());
} else
++it;
}
Expand Down
2 changes: 1 addition & 1 deletion src/contract/polls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ double ReturnVerifiedVotingBalance(std::string sXML, bool bCreatedAfterSecurityU
double dTotalVotedBalance = RoundFromString(ExtractXML(sPayload,"<TOTALVOTEDBALANCE>","</TOTALVOTEDBALANCE>"),2);
double dLegacyBalance = RoundFromString(ExtractXML(sXML,"<BALANCE>","</BALANCE>"),0);

if (fDebug10) LogPrintf("Total Voted Balance %f, Legacy Balance %f", dTotalVotedBalance, dLegacyBalance);
LogPrint(BCLog::LogFlags::NOISY, "Total Voted Balance %f, Legacy Balance %f", dTotalVotedBalance, dLegacyBalance);
if (!bCreatedAfterSecurityUpgrade) return dLegacyBalance;

double dCounted = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void CDBEnv::MakeMock()
if (fShutdown)
throw runtime_error("CDBEnv::MakeMock(): during shutdown");

LogPrint("db", "CDBEnv::MakeMock()");
LogPrint(BCLog::LogFlags::WALLETDB, "CDBEnv::MakeMock()");

dbenv.set_cachesize(1, 0, 1);
dbenv.set_lg_bsize(10485760*4);
Expand Down Expand Up @@ -452,7 +452,7 @@ void CDBEnv::Flush(bool fShutdown)
int64_t nStart = GetTimeMillis();
// Flush log data to the actual data file
// on all files that are not in use
LogPrint("db", "Flush(%s)%s", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
LogPrint(BCLog::LogFlags::WALLETDB, "Flush(%s)%s", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
if (!fDbEnvInit)
return;
{
Expand All @@ -462,23 +462,23 @@ void CDBEnv::Flush(bool fShutdown)
{
string strFile = (*mi).first;
int nRefCount = (*mi).second;
LogPrint("db", "%s refcount=%d", strFile, nRefCount);
LogPrint(BCLog::LogFlags::WALLETDB, "%s refcount=%d", strFile, nRefCount);
if (nRefCount == 0)
{
// Move log data to the dat file
CloseDb(strFile);
LogPrint("db", "%s checkpoint", strFile);
LogPrint(BCLog::LogFlags::WALLETDB, "%s checkpoint", strFile);
dbenv.txn_checkpoint(0, 0, 0);
LogPrint("db", "%s detach", strFile);
LogPrint(BCLog::LogFlags::WALLETDB, "%s detach", strFile);
if (!fMockDb)
dbenv.lsn_reset(strFile.c_str(), 0);
LogPrint("db", "%s closed", strFile);
LogPrint(BCLog::LogFlags::WALLETDB, "%s closed", strFile);
mapFileUseCount.erase(mi++);
}
else
mi++;
}
LogPrint("db", "DBFlush(%s)%s ended %15" PRId64 "ms", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart);
LogPrint(BCLog::LogFlags::WALLETDB, "DBFlush(%s)%s ended %15" PRId64 "ms", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart);
if (fShutdown)
{
char** listp;
Expand Down
26 changes: 7 additions & 19 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,28 +600,16 @@ bool AppInit2(ThreadHandlerPtr threads)

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

fDebug = false;

if (GetArg("-debug", "false") == "true")
{
fDebug = true;
LogPrintf("Entering debug mode.");
}

fDebug2 = false;

if (GetArg("-debug2", "false") == "true")
{
fDebug2 = true;
LogPrintf("Entering GRC debug mode 2.");
LogPrintf("Enabling debug category VERBOSE from legacy debug.");
LogInstance().EnableCategory(BCLog::LogFlags::VERBOSE);
}

fDebug10 = false;

if (GetArg("-debug10", "false") == "true")
{
fDebug10 = true;
LogPrintf("Entering GRC debug mode 10.");
LogPrintf("Entering debug category NOISY from legacy debug mode 10.");
LogInstance().EnableCategory(BCLog::LogFlags::NOISY);
}


Expand Down Expand Up @@ -741,7 +729,7 @@ bool AppInit2(ThreadHandlerPtr threads)
fDevbuildCripple = true;
LogPrintf("WARNING: Running development version outside of testnet!\n"
"Staking and sending transactions will be disabled.");
if( (GetArg("-devbuild", "") == "override") && fDebug )
if( (GetArg("-devbuild", "") == "override") && LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE))
fDevbuildCripple = false;
}

Expand Down Expand Up @@ -1106,7 +1094,7 @@ bool AppInit2(ThreadHandlerPtr threads)
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));

uiInterface.InitMessage(_("Loading addresses..."));
if (fDebug10) LogPrintf("Loading addresses...");
LogPrint(BCLog::LogFlags::NOISY, "Loading addresses...");
nStart = GetTimeMillis();

{
Expand Down Expand Up @@ -1135,7 +1123,7 @@ bool AppInit2(ThreadHandlerPtr threads)
RandAddSeedPerfmon();

//// debug print
if (fDebug)
if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE))
{
LogPrintf("mapBlockIndex.size() = %" PRIszu, mapBlockIndex.size());
LogPrintf("nBestHeight = %d", nBestHeight);
Expand Down
31 changes: 15 additions & 16 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static bool SelectBlockFromCandidates(
}
}

if (fDebug && GetBoolArg("-printstakemodifier"))
if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier"))
LogPrintf("SelectBlockFromCandidates: selection hash=%s", hashBest.ToString());

return fSelected;
Expand Down Expand Up @@ -280,10 +280,9 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
int64_t nModifierTime = 0;
if (!GetLastStakeModifier(pindexPrev, nStakeModifier, nModifierTime))
return error("ComputeNextStakeModifier: unable to get last modifier");
if (fDebug10)
{
LogPrintf("ComputeNextStakeModifier: prev modifier=0x%016" PRIx64 " time=%s", nStakeModifier, DateTimeStrFormat(nModifierTime));
}

LogPrint(BCLog::LogFlags::VERBOSE, "ComputeNextStakeModifier: prev modifier=0x%016" PRIx64 " time=%s", nStakeModifier, DateTimeStrFormat(nModifierTime));

if (nModifierTime / nModifierInterval >= pindexPrev->GetBlockTime() / nModifierInterval)
return true;

Expand Down Expand Up @@ -334,12 +333,12 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
nStakeModifierNew |= (((uint64_t)pindex->GetStakeEntropyBit()) << nRound);
// add the selected block from candidates to selected list
mapSelectedBlocks.insert(make_pair(pindex->GetBlockHash(), pindex));
if (fDebug && GetBoolArg("-printstakemodifier"))
if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier"))
LogPrintf("ComputeNextStakeModifier: selected round %d stop=%s height=%d bit=%d", nRound, DateTimeStrFormat(nSelectionIntervalStop), pindex->nHeight, pindex->GetStakeEntropyBit());
}

// Print selection map for visualization of the selected blocks
if (fDebug && GetBoolArg("-printstakemodifier"))
if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier"))
{
string strSelectionMap = "";
// '-' indicates proof-of-work blocks not selected
Expand All @@ -361,7 +360,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
LogPrintf("ComputeNextStakeModifier: selection height [%d, %d] map %s", nHeightFirstCandidate,
pindexPrev->nHeight, strSelectionMap);
}
if (fDebug)
if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE))
{
LogPrintf("ComputeNextStakeModifier: new modifier=0x%016" PRIx64 " time=%s", nStakeModifierNew, DateTimeStrFormat(pindexPrev->GetBlockTime()));
}
Expand Down Expand Up @@ -600,14 +599,14 @@ bool CheckProofOfStakeV8(
bnTarget *= Weight;


if(fDebug) LogPrintf(
"CheckProofOfStakeV8:%s Time1 %.f, Time2 %.f, Time3 %.f, Bits %u, Weight %.f\n"
" Stk %72s\n"
" Trg %72s", generated_by_me?" Local,":"",
(double)header.nTime, (double)txPrev.nTime, (double)tx.nTime,
Block.nBits, (double)Weight,
CBigNum(hashProofOfStake).GetHex(), bnTarget.GetHex()
);
LogPrint(BCLog::LogFlags::VERBOSE,
"CheckProofOfStakeV8:%s Time1 %.f, Time2 %.f, Time3 %.f, Bits %u, Weight %.f\n"
" Stk %72s\n"
" Trg %72s", generated_by_me?" Local,":"",
(double)header.nTime, (double)txPrev.nTime, (double)tx.nTime,
Block.nBits, (double)Weight,
CBigNum(hashProofOfStake).GetHex(), bnTarget.GetHex()
);

// Now check if proof-of-stake hash meets target protocol
return bnHashProof <= bnTarget;
Expand Down
3 changes: 3 additions & 0 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::TALLY, "tally"},
{BCLog::ACCRUAL, "accrual"},
{BCLog::CONTRACT, "contract"},
{BCLog::MINER, "miner"},
{BCLog::VERBOSE, "verbose"},
{BCLog::NOISY, "noisy"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
};
Expand Down
3 changes: 3 additions & 0 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ namespace BCLog {
TALLY = (1 << 25),
ACCRUAL = (1 << 26),
CONTRACT = (1 << 27),
MINER = (1 << 28),
VERBOSE = (1 << 29), // This corresponds to the old horizontal category "debug".
NOISY = (1 << 30), // This corresponds to the old horizontal category "debug10".
ALL = ~(uint32_t)0,
};

Expand Down
Loading

0 comments on commit bea8bc6

Please sign in to comment.