Skip to content
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ set(UTIL_SOURCES
./src/compat/glibcxx_sanity.cpp
./src/chainparamsbase.cpp
./src/clientversion.cpp
./src/logging.cpp
./src/random.cpp
./src/rpc/protocol.cpp
./src/sync.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ BITCOIN_CORE_H = \
keystore.h \
leveldbwrapper.h \
limitedmap.h \
logging.h \
main.h \
masternode.h \
masternode-payments.h \
Expand Down Expand Up @@ -418,6 +419,7 @@ libbitcoin_util_a_SOURCES = \
compat/glibc_sanity.cpp \
compat/glibcxx_sanity.cpp \
compat/strnlen.cpp \
logging.cpp \
random.cpp \
rpc/protocol.cpp \
support/cleanse.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void CActiveMasternode::ManageStatus()

if (!fMasterNode) return;

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

//need correct blocks to send ping
if (!Params().IsRegTestNet() && !masternodeSync.IsBlockchainSynced()) {
Expand Down
4 changes: 2 additions & 2 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ bool InitHTTPServer()
// Update libevent's log handling. Returns false if our version of
// libevent doesn't support debug logging, in which case we should
// clear the BCLog::LIBEVENT flag.
if (!UpdateHTTPServerLogging(logCategories & BCLog::LIBEVENT)) {
logCategories &= ~BCLog::LIBEVENT;
if (!UpdateHTTPServerLogging(g_logger->WillLogCategory(BCLog::LIBEVENT))) {
g_logger->DisableCategory(BCLog::LIBEVENT);
}

#ifdef WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/httpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void InterruptHTTPServer();
/** Stop HTTP server */
void StopHTTPServer();

/** Change logging level for libevent. Removes BCLog::LIBEVENT from logCategories if
/** Change logging level for libevent. Removes BCLog::LIBEVENT from log categories if
* libevent doesn't support debug logging.*/
bool UpdateHTTPServerLogging(bool enable);

Expand Down
50 changes: 32 additions & 18 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void HandleSIGTERM(int)

void HandleSIGHUP(int)
{
fReopenDebugLog = true;
g_logger->m_reopen_file = true;
}

#ifndef WIN32
Expand Down Expand Up @@ -507,6 +507,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-help-debug", _("Show all debugging options (usage: --help -help-debug)"));
strUsage += HelpMessageOpt("-logips", strprintf(_("Include IP addresses in debug output (default: %u)"), 0));
strUsage += HelpMessageOpt("-logtimestamps", strprintf(_("Prepend debug output with timestamp (default: %u)"), 1));
strUsage += HelpMessageOpt("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS));
if (GetBoolArg("-help-debug", false)) {
strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf(_("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default:%u)"), 15));
strUsage += HelpMessageOpt("-relaypriority", strprintf(_("Require high priority for relaying free or low-fee transactions (default:%u)"), 1));
Expand Down Expand Up @@ -901,12 +902,28 @@ static std::string ResolveErrMsg(const char * const optname, const std::string&

void InitLogging()
{
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
fLogIPs = GetBoolArg("-logips", false);
//g_logger->m_print_to_file = !IsArgNegated("-debuglogfile");
g_logger->m_print_to_file = true;
g_logger->m_file_path = AbsPathForConfigVal(GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));

// Add newlines to the logfile to distinguish this execution from the last
// one; called before console logging is set up, so this is only sent to
// debug.log.
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);

g_logger->m_print_to_console = GetBoolArg("-printtoconsole", !GetBoolArg("-daemon", false));
g_logger->m_log_timestamps = GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
g_logger->m_log_time_micros = GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);

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

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

/** Initialize pivx.
Expand Down Expand Up @@ -937,23 +954,19 @@ bool AppInit2()
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))
if (!g_logger->EnableCategory(cat)) {
UIWarning(strprintf(_("Unsupported logging category %s=%s."), "-debug", cat));
else
logCategories |= flag;
}
}
}

// Now remove the logging categories which were explicitly excluded
if (mapMultiArgs.count("-debugexclude") > 0) {
const std::vector<std::string>& excludedCategories = mapMultiArgs.at("-debugexclude");
for (const auto& cat : excludedCategories) {
uint32_t flag;
if (!GetLogCategory(&flag, &cat))
if (!g_logger->DisableCategory(cat)) {
UIWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
else
logCategories &= ~flag;
}
}
}

Expand Down Expand Up @@ -1062,15 +1075,16 @@ bool AppInit2()
#ifndef WIN32
CreatePidFile(GetPidFile(), getpid());
#endif
if (GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE))
ShrinkDebugFile();
if (fPrintToDebugLog && !OpenDebugLog()) {
return UIError(strprintf("Could not open debug log file %s", GetDebugLogPath().string()));
if (g_logger->m_print_to_file) {
if (GetBoolArg("-shrinkdebugfile", g_logger->DefaultShrinkDebugFile()))
g_logger->ShrinkDebugFile();
if (!g_logger->OpenDebugLog())
return UIError(strprintf("Could not open debug log file %s", g_logger->m_file_path.string()));
}
#ifdef ENABLE_WALLET
LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
#endif
if (!fLogTimestamps)
if (!g_logger->m_log_timestamps)
LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()));
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
LogPrintf("Using data directory %s\n", strDataDir);
Expand Down
Loading