aboutsummaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2021-04-18 19:03:26 -0400
committerRussell Yanofsky <russ@yanofsky.org>2021-04-19 06:11:38 -0400
commit1fb7fcfa52569a652d3ea55c210b725e60b7d86f (patch)
treebffcce203df55bd0973e7222cdf673471327d78a /src/init
parent90469c16906ab451bb1250df5e51563870a7ef3b (diff)
downloadbitcoin-1fb7fcfa52569a652d3ea55c210b725e60b7d86f.tar.xz
Move common logging GetArgs code to init/common
Diffstat (limited to 'src/init')
-rw-r--r--src/init/common.cpp39
-rw-r--r--src/init/common.h2
2 files changed, 41 insertions, 0 deletions
diff --git a/src/init/common.cpp b/src/init/common.cpp
index caabd5db82..d905fecdd8 100644
--- a/src/init/common.cpp
+++ b/src/init/common.cpp
@@ -76,4 +76,43 @@ void AddLoggingArgs(ArgsManager& argsman)
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
}
+
+void SetLoggingOptions(const ArgsManager& args)
+{
+ LogInstance().m_print_to_file = !args.IsArgNegated("-debuglogfile");
+ LogInstance().m_file_path = AbsPathForConfigVal(args.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
+ LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", !args.GetBoolArg("-daemon", false));
+ LogInstance().m_log_timestamps = args.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
+ LogInstance().m_log_time_micros = args.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
+#ifdef HAVE_THREAD_LOCAL
+ LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
+#endif
+ LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
+
+ fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
+}
+
+void SetLoggingCategories(const ArgsManager& args)
+{
+ if (args.IsArgSet("-debug")) {
+ // Special-case: if -debug=0/-nodebug is set, turn off debugging messages
+ const std::vector<std::string> categories = args.GetArgs("-debug");
+
+ 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));
+ }
+ }
+ }
+ }
+
+ // Now remove the logging categories which were explicitly excluded
+ for (const std::string& cat : args.GetArgs("-debugexclude")) {
+ if (!LogInstance().DisableCategory(cat)) {
+ InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
+ }
+ }
+}
} // namespace init
diff --git a/src/init/common.h b/src/init/common.h
index fce6e679c2..58e33cfd1c 100644
--- a/src/init/common.h
+++ b/src/init/common.h
@@ -19,6 +19,8 @@ void UnsetGlobals();
*/
bool SanityChecks();
void AddLoggingArgs(ArgsManager& args);
+void SetLoggingOptions(const ArgsManager& args);
+void SetLoggingCategories(const ArgsManager& args);
} // namespace init
#endif // BITCOIN_INIT_COMMON_H