From f55f4fcf05a53fdf618b4c69ddcf4c43b14e84c2 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Wed, 11 Apr 2018 10:03:21 -0700 Subject: util: Establish global logger object. The object encapsulates logging configuration, and in a later commit, set up routines will also be moved into the class. --- src/init.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 99dab605a..814fd3944 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -305,7 +305,7 @@ static void HandleSIGTERM(int) static void HandleSIGHUP(int) { - fReopenDebugLog = true; + g_logger->fReopenDebugLog = true; } #ifndef WIN32 @@ -831,10 +831,11 @@ void InitLogging() // debug.log. LogPrintf("\n\n\n\n\n"); - fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); - fPrintToDebugLog = !gArgs.IsArgNegated("-debuglogfile"); - fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); - fLogTimeMicros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); + g_logger->fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); + g_logger->fPrintToDebugLog = !gArgs.IsArgNegated("-debuglogfile"); + g_logger->fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); + g_logger->fLogTimeMicros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); + fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); std::string version_string = FormatFullVersion(); @@ -1230,7 +1231,7 @@ bool AppInitMain() #ifndef WIN32 CreatePidFile(GetPidFile(), getpid()); #endif - if (fPrintToDebugLog) { + if (g_logger->fPrintToDebugLog) { if (gArgs.GetBoolArg("-shrinkdebugfile", logCategories == BCLog::NONE)) { // 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 @@ -1241,7 +1242,7 @@ bool AppInitMain() } } - if (!fLogTimestamps) + if (!g_logger->fLogTimestamps) LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime())); LogPrintf("Default data directory %s\n", GetDefaultDataDir().string()); LogPrintf("Using data directory %s\n", GetDataDir().string()); -- cgit v1.2.3 From 6a6d764ca5616e5d1f1848b0010613c49bd38e61 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Wed, 11 Apr 2018 11:12:51 -0700 Subject: util: Move debug file management functions into Logger. --- src/init.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 814fd3944..c14597d51 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1235,10 +1235,11 @@ bool AppInitMain() if (gArgs.GetBoolArg("-shrinkdebugfile", logCategories == BCLog::NONE)) { // 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 - ShrinkDebugFile(); + g_logger->ShrinkDebugFile(); } - if (!OpenDebugLog()) { - return InitError(strprintf("Could not open debug log file %s", GetDebugLogPath().string())); + if (!g_logger->OpenDebugLog()) { + return InitError(strprintf("Could not open debug log file %s", + g_logger->GetDebugLogPath().string())); } } -- cgit v1.2.3 From 3316a9ebb66171937efddb213daed64fe51c4082 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Wed, 11 Apr 2018 13:02:01 -0700 Subject: util: Encapsulate logCategories within BCLog::Logger. --- src/init.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index c14597d51..ccaa09a85 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -968,7 +968,7 @@ bool AppInitParameterInteraction() InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)); continue; } - logCategories |= flag; + g_logger->EnableCategory(static_cast(flag)); } } } @@ -980,7 +980,7 @@ bool AppInitParameterInteraction() InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat)); continue; } - logCategories &= ~flag; + g_logger->DisableCategory(static_cast(flag)); } // Check for -debugnet @@ -1232,7 +1232,7 @@ bool AppInitMain() CreatePidFile(GetPidFile(), getpid()); #endif if (g_logger->fPrintToDebugLog) { - if (gArgs.GetBoolArg("-shrinkdebugfile", logCategories == BCLog::NONE)) { + if (gArgs.GetBoolArg("-shrinkdebugfile", g_logger->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 g_logger->ShrinkDebugFile(); -- cgit v1.2.3 From 1eac317f25b905e97e311130ab19c3b0d257fc04 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Wed, 11 Apr 2018 14:06:35 -0700 Subject: util: Refactor GetLogCategory. Changing parameter types from pointers to references and uint32_t to BCLog::LogFlags simplies calling code. --- src/init.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index ccaa09a85..c0eb746d7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -963,24 +963,18 @@ bool AppInitParameterInteraction() if (std::none_of(categories.begin(), categories.end(), [](std::string cat){return cat == "0" || cat == "none";})) { for (const auto& cat : categories) { - uint32_t flag = 0; - if (!GetLogCategory(&flag, &cat)) { + if (!g_logger->EnableCategory(cat)) { InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)); - continue; } - g_logger->EnableCategory(static_cast(flag)); } } } // Now remove the logging categories which were explicitly excluded for (const std::string& cat : gArgs.GetArgs("-debugexclude")) { - uint32_t flag = 0; - if (!GetLogCategory(&flag, &cat)) { + if (!g_logger->DisableCategory(cat)) { InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat)); - continue; } - g_logger->DisableCategory(static_cast(flag)); } // Check for -debugnet -- cgit v1.2.3 From 8e7b961388920144993d0bd56d93f89e5c60fbff Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Fri, 20 Apr 2018 00:42:32 -0700 Subject: scripted-diff: Rename BCLog::Logger member variables. -BEGIN VERIFY SCRIPT- sed -i "s/fileout/m_fileout/" src/logging.h src/logging.cpp sed -i "s/mutexDebugLog/m_file_mutex/" src/logging.h src/logging.cpp sed -i "s/vMsgsBeforeOpenLog/m_msgs_before_open/" src/logging.h src/logging.cpp sed -i "s/logCategories/m_categories/" src/logging.h src/logging.cpp sed -i "s/fPrintToConsole/m_print_to_console/" src/logging.h src/logging.cpp src/init.cpp sed -i "s/fPrintToDebugLog/m_print_to_file/" src/logging.h src/logging.cpp src/init.cpp src/test/test_bitcoin.cpp src/bench/bench_bitcoin.cpp sed -i "s/fLogTimestamps/m_log_timestamps/" src/logging.h src/logging.cpp src/init.cpp sed -i "s/fLogTimeMicros/m_log_time_micros/" src/logging.h src/logging.cpp src/init.cpp sed -i "s/fReopenDebugLog/m_reopen_file/" src/logging.h src/logging.cpp src/init.cpp sed -i "s/fStartedNewLine/m_started_new_line/" src/logging.h src/logging.cpp -END VERIFY SCRIPT- --- src/init.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index c0eb746d7..7bc2f6302 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -305,7 +305,7 @@ static void HandleSIGTERM(int) static void HandleSIGHUP(int) { - g_logger->fReopenDebugLog = true; + g_logger->m_reopen_file = true; } #ifndef WIN32 @@ -831,10 +831,10 @@ void InitLogging() // debug.log. LogPrintf("\n\n\n\n\n"); - g_logger->fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); - g_logger->fPrintToDebugLog = !gArgs.IsArgNegated("-debuglogfile"); - g_logger->fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); - g_logger->fLogTimeMicros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); + g_logger->m_print_to_console = gArgs.GetBoolArg("-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); + g_logger->m_print_to_file = !gArgs.IsArgNegated("-debuglogfile"); + g_logger->m_log_timestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); + g_logger->m_log_time_micros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); @@ -1225,7 +1225,7 @@ bool AppInitMain() #ifndef WIN32 CreatePidFile(GetPidFile(), getpid()); #endif - if (g_logger->fPrintToDebugLog) { + if (g_logger->m_print_to_file) { if (gArgs.GetBoolArg("-shrinkdebugfile", g_logger->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 @@ -1237,7 +1237,7 @@ bool AppInitMain() } } - if (!g_logger->fLogTimestamps) + if (!g_logger->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()); -- cgit v1.2.3 From 8c2d695c4a45bdd9378c7970b0fcba6e1efc01f9 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Fri, 20 Apr 2018 01:11:44 -0700 Subject: util: Store debug log file path in BCLog::Logger member. This breaks the cyclic between logging and util. --- src/init.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 7bc2f6302..6423d8702 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -826,13 +826,15 @@ static std::string ResolveErrMsg(const char * const optname, const std::string& */ void InitLogging() { + g_logger->m_print_to_file = !gArgs.IsArgNegated("-debuglogfile"); + g_logger->m_file_path = AbsPathForConfigVal(gArgs.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"); g_logger->m_print_to_console = gArgs.GetBoolArg("-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); - g_logger->m_print_to_file = !gArgs.IsArgNegated("-debuglogfile"); g_logger->m_log_timestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); g_logger->m_log_time_micros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); @@ -1233,7 +1235,7 @@ bool AppInitMain() } if (!g_logger->OpenDebugLog()) { return InitError(strprintf("Could not open debug log file %s", - g_logger->GetDebugLogPath().string())); + g_logger->m_file_path.string())); } } -- cgit v1.2.3