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

Port of the Bitcoin Logger to Gridcoin #1600

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ GRIDCOIN_CORE_H = \
kernel.h \
key.h \
keystore.h \
logging.h \
main.h \
miner.h \
mruset.h \
Expand Down Expand Up @@ -134,6 +135,8 @@ GRIDCOIN_CORE_H = \
util/memory.h \
util/reverse_iterator.h \
util/strencodings.h \
util/threadnames.h \
util/time.h \
util.h \
version.h \
walletdb.h \
Expand All @@ -160,6 +163,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
kernel.cpp \
key.cpp \
keystore.cpp \
logging.cpp \
main.cpp \
miner.cpp \
neuralnet/claim.cpp \
Expand All @@ -178,6 +182,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
rpcblockchain.cpp \
rpcclient.cpp \
rpcdump.cpp \
rpcmisc.cpp \
rpcmining.cpp \
rpcnet.cpp \
rpcprotocol.cpp \
Expand All @@ -201,6 +206,8 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
uint256.cpp \
upgrade.cpp \
util/strencodings.cpp \
util/threadnames.cpp \
util/time.cpp \
util.cpp \
version.cpp \
wallet.cpp \
Expand Down
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;

if (fDebug10) LogPrint("addr", "Moving %s to tried", addr.ToString());
LogPrint("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("addr", "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err);
LogPrint("addrman", "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err);
}
#endif
}
Expand All @@ -419,7 +419,7 @@ class CAddrMan
Check();
}
if (fRet)
LogPrint("addr","Added %s from %s: %i tried, %i new", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
LogPrint("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)
if (fDebug) LogPrint("addr","Added %i addresses from %s: %i tried, %i new", nAdd, source.ToString(), nTried, nNew);
LogPrint("addrman","Added %i addresses from %s: %i tried, %i new", nAdd, source.ToString(), nTried, nNew);
return nAdd > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void BanMan::SweepBanned()

m_is_dirty = true;
notify_ui = true;
LogPrint("network", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString());
LogPrint("net", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString());
} else
++it;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gridcoinresearchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ bool AppInit(int argc, char* argv[])
exit(ret);
}

InitLogging();

fRet = AppInit2(threads);
}
catch (std::exception& e) {
Expand Down
118 changes: 113 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,111 @@ bool InitSanityCheck(void)
return true;
}

/**
* Initialize global loggers.
*
* Note that this is called very early in the process lifetime, so you should be
* careful about what global state you rely on here.
*/
void InitLogging()
{
fPrintToConsole = GetBoolArg("-printtoconsole");
fPrintToDebugger = GetBoolArg("-printtodebugger");
fLogTimestamps = GetBoolArg("-logtimestamps", true);

LogInstance().m_print_to_file = !IsArgNegated("-debuglogfile");
LogInstance().m_file_path = AbsPathForConfigVal(GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));

//printf("LogInstance().m_file_path = %s\n", LogInstance().m_file_path.c_str());
//printf("LogInstance().m_print_to_file = %i\n", LogInstance().m_print_to_file);

LogInstance().m_print_to_console = fPrintToConsole;
LogInstance().m_log_timestamps = fLogTimestamps;
LogInstance().m_log_time_micros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
LogInstance().m_log_threadnames = GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);

//BCLog::LogFlags flags = BCLog::LogFlags::ALL;

//LogInstance().EnableCategory(flags);

//printf("LogInstance().GetCategoryMask() = %x\n", LogInstance().GetCategoryMask());

fLogIPs = GetBoolArg("-logips", DEFAULT_LOGIPS);

if (LogInstance().m_print_to_file)
{
// Only shrink debug file at start if log archiving is set to false.
if (!GetBoolArg("-logarchivedaily", true) && GetBoolArg("-shrinkdebugfile", LogInstance().DefaultShrinkDebugFile()))
{
// Do this first since it both loads a bunch of debug.log into memory,
// and because this needs to happen before any other debug.log printing
LogInstance().ShrinkDebugFile();
}
}

if (IsArgSet("-debug"))
{
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
std::vector<std::string> categories;

if (mapArgs.count("-debug") && mapMultiArgs["-debug"].size() > 0)
{
for (auto const& sSubParam : mapMultiArgs["-debug"])
{
categories.push_back(sSubParam);
}
}

if (std::none_of(categories.begin(), categories.end(),
[](std::string cat){return cat == "0" || cat == "none";}))
{
for (const auto& cat : categories)
{
if (!LogInstance().EnableCategory(cat))
{
InitWarning(strprintf("Unsupported logging category %s=%s.", "-debug", cat));
}
}
}
}

std::vector<std::string> excluded_categories;

if (mapArgs.count("-debugexclude") && mapMultiArgs["-debugexclude"].size() > 0)
{
for (auto const& sSubParam : mapMultiArgs["-debugexclude"])
{
excluded_categories.push_back(sSubParam);
}
}

// Now remove the logging categories which were explicitly excluded
for (const std::string& cat : excluded_categories)
{
if (!LogInstance().DisableCategory(cat))
{
InitWarning(strprintf("Unsupported logging category %s=%s.", "-debugexclude", cat));
}
}

if (!LogInstance().StartLogging())
{
strprintf("Could not open debug log file %s", LogInstance().m_file_path.string());
}

if (!LogInstance().m_log_timestamps)
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
LogPrintf("Using data directory %s\n", GetDataDir().string());

std::string version_string = FormatFullVersion();
#ifdef DEBUG
version_string += " (debug build)";
#else
version_string += " (release build)";
#endif
LogPrintf(PACKAGE_NAME " version %s\n", version_string);
}



Expand Down Expand Up @@ -553,11 +658,6 @@ bool AppInit2(ThreadHandlerPtr threads)
if(!fQtActive)
fServer = true;

fPrintToConsole = GetBoolArg("-printtoconsole");
fPrintToDebugger = GetBoolArg("-printtodebugger");
fLogTimestamps = GetBoolArg("-logtimestamps");
fLogTimestamps = true;

if (mapArgs.count("-timeout"))
{
int nNewTimeout = GetArg("-timeout", 5000);
Expand Down Expand Up @@ -1079,6 +1179,14 @@ bool AppInit2(ThreadHandlerPtr threads)
g_banman->DumpBanlist();
}, DUMP_BANS_INTERVAL * 1000);

// Primitive, but this is what the scraper does in the scraper houskeeping loop. It checks to see if the logs need to be archived
// by default every 5 mins. Note that passing false to the archive function means that if we have not crossed over the day boundary,
// it does nothing, so this is a very inexpensive call. Also if -logarchivedaily is set to false, then this will be a no-op.
scheduler.scheduleEvery([]{
fs::path plogfile_out;
LogInstance().archive(false, plogfile_out);
}, 300 * 1000);

/** If this is not TestNet we check for updates on startup and daily **/
/** We still add to the scheduler regardless of the users choice however the choice is respected when they opt out**/
if (!fTestNet)
Expand Down
2 changes: 2 additions & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

extern CWallet* pwalletMain;

void InitLogging();

void StartShutdown();

bool ShutdownRequested();
Expand Down
Loading