Skip to content

Commit 1fb7fcf

Browse files
committed
Move common logging GetArgs code to init/common
1 parent 90469c1 commit 1fb7fcf

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

src/init.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -755,17 +755,7 @@ void InitParameterInteraction(ArgsManager& args)
755755
*/
756756
void InitLogging(const ArgsManager& args)
757757
{
758-
LogInstance().m_print_to_file = !args.IsArgNegated("-debuglogfile");
759-
LogInstance().m_file_path = AbsPathForConfigVal(args.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
760-
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", !args.GetBoolArg("-daemon", false));
761-
LogInstance().m_log_timestamps = args.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
762-
LogInstance().m_log_time_micros = args.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
763-
#ifdef HAVE_THREAD_LOCAL
764-
LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
765-
#endif
766-
LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
767-
768-
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
758+
init::SetLoggingOptions(args);
769759

770760
std::string version_string = FormatFullVersion();
771761
#ifdef DEBUG
@@ -941,26 +931,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
941931
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
942932

943933
// ********************************************************* Step 3: parameter-to-internal-flags
944-
if (args.IsArgSet("-debug")) {
945-
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
946-
const std::vector<std::string> categories = args.GetArgs("-debug");
947-
948-
if (std::none_of(categories.begin(), categories.end(),
949-
[](std::string cat){return cat == "0" || cat == "none";})) {
950-
for (const auto& cat : categories) {
951-
if (!LogInstance().EnableCategory(cat)) {
952-
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debug", cat));
953-
}
954-
}
955-
}
956-
}
957-
958-
// Now remove the logging categories which were explicitly excluded
959-
for (const std::string& cat : args.GetArgs("-debugexclude")) {
960-
if (!LogInstance().DisableCategory(cat)) {
961-
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
962-
}
963-
}
934+
init::SetLoggingCategories(args);
964935

965936
fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
966937
fCheckpointsEnabled = args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED);

src/init/common.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,43 @@ void AddLoggingArgs(ArgsManager& argsman)
7676
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);
7777
argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
7878
}
79+
80+
void SetLoggingOptions(const ArgsManager& args)
81+
{
82+
LogInstance().m_print_to_file = !args.IsArgNegated("-debuglogfile");
83+
LogInstance().m_file_path = AbsPathForConfigVal(args.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
84+
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", !args.GetBoolArg("-daemon", false));
85+
LogInstance().m_log_timestamps = args.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
86+
LogInstance().m_log_time_micros = args.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
87+
#ifdef HAVE_THREAD_LOCAL
88+
LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
89+
#endif
90+
LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
91+
92+
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
93+
}
94+
95+
void SetLoggingCategories(const ArgsManager& args)
96+
{
97+
if (args.IsArgSet("-debug")) {
98+
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
99+
const std::vector<std::string> categories = args.GetArgs("-debug");
100+
101+
if (std::none_of(categories.begin(), categories.end(),
102+
[](std::string cat){return cat == "0" || cat == "none";})) {
103+
for (const auto& cat : categories) {
104+
if (!LogInstance().EnableCategory(cat)) {
105+
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debug", cat));
106+
}
107+
}
108+
}
109+
}
110+
111+
// Now remove the logging categories which were explicitly excluded
112+
for (const std::string& cat : args.GetArgs("-debugexclude")) {
113+
if (!LogInstance().DisableCategory(cat)) {
114+
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
115+
}
116+
}
117+
}
79118
} // namespace init

src/init/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void UnsetGlobals();
1919
*/
2020
bool SanityChecks();
2121
void AddLoggingArgs(ArgsManager& args);
22+
void SetLoggingOptions(const ArgsManager& args);
23+
void SetLoggingCategories(const ArgsManager& args);
2224
} // namespace init
2325

2426
#endif // BITCOIN_INIT_COMMON_H

0 commit comments

Comments
 (0)