Skip to content

Commit 5bed2ab

Browse files
committed
Move common logging start code to init/common
1 parent 1fb7fcf commit 5bed2ab

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

src/init.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,38 +1122,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
11221122
// Detailed error printed inside CreatePidFile().
11231123
return false;
11241124
}
1125-
if (LogInstance().m_print_to_file) {
1126-
if (args.GetBoolArg("-shrinkdebugfile", LogInstance().DefaultShrinkDebugFile())) {
1127-
// Do this first since it both loads a bunch of debug.log into memory,
1128-
// and because this needs to happen before any other debug.log printing
1129-
LogInstance().ShrinkDebugFile();
1130-
}
1131-
}
1132-
if (!LogInstance().StartLogging()) {
1133-
return InitError(strprintf(Untranslated("Could not open debug log file %s"),
1134-
LogInstance().m_file_path.string()));
1135-
}
1136-
1137-
if (!LogInstance().m_log_timestamps)
1138-
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
1139-
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
1140-
LogPrintf("Using data directory %s\n", GetDataDir().string());
1141-
1142-
// Only log conf file usage message if conf file actually exists.
1143-
fs::path config_file_path = GetConfigFile(args.GetArg("-conf", BITCOIN_CONF_FILENAME));
1144-
if (fs::exists(config_file_path)) {
1145-
LogPrintf("Config file: %s\n", config_file_path.string());
1146-
} else if (args.IsArgSet("-conf")) {
1147-
// Warn if no conf file exists at path provided by user
1148-
InitWarning(strprintf(_("The specified config file %s does not exist"), config_file_path.string()));
1149-
} else {
1150-
// Not categorizing as "Warning" because it's the default behavior
1151-
LogPrintf("Config file: %s (not found, skipping)\n", config_file_path.string());
1125+
if (!init::StartLogging(args)) {
1126+
// Detailed error printed inside StartLogging().
1127+
return false;
11521128
}
11531129

1154-
// Log the config arguments to debug.log
1155-
args.LogArgs();
1156-
11571130
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
11581131

11591132
// Warn about relative -datadir path.

src/init/common.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,41 @@ void SetLoggingCategories(const ArgsManager& args)
115115
}
116116
}
117117
}
118+
119+
bool StartLogging(const ArgsManager& args)
120+
{
121+
if (LogInstance().m_print_to_file) {
122+
if (args.GetBoolArg("-shrinkdebugfile", LogInstance().DefaultShrinkDebugFile())) {
123+
// Do this first since it both loads a bunch of debug.log into memory,
124+
// and because this needs to happen before any other debug.log printing
125+
LogInstance().ShrinkDebugFile();
126+
}
127+
}
128+
if (!LogInstance().StartLogging()) {
129+
return InitError(strprintf(Untranslated("Could not open debug log file %s"),
130+
LogInstance().m_file_path.string()));
131+
}
132+
133+
if (!LogInstance().m_log_timestamps)
134+
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
135+
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
136+
LogPrintf("Using data directory %s\n", GetDataDir().string());
137+
138+
// Only log conf file usage message if conf file actually exists.
139+
fs::path config_file_path = GetConfigFile(args.GetArg("-conf", BITCOIN_CONF_FILENAME));
140+
if (fs::exists(config_file_path)) {
141+
LogPrintf("Config file: %s\n", config_file_path.string());
142+
} else if (args.IsArgSet("-conf")) {
143+
// Warn if no conf file exists at path provided by user
144+
InitWarning(strprintf(_("The specified config file %s does not exist"), config_file_path.string()));
145+
} else {
146+
// Not categorizing as "Warning" because it's the default behavior
147+
LogPrintf("Config file: %s (not found, skipping)\n", config_file_path.string());
148+
}
149+
150+
// Log the config arguments to debug.log
151+
args.LogArgs();
152+
153+
return true;
154+
}
118155
} // namespace init

src/init/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bool SanityChecks();
2121
void AddLoggingArgs(ArgsManager& args);
2222
void SetLoggingOptions(const ArgsManager& args);
2323
void SetLoggingCategories(const ArgsManager& args);
24+
bool StartLogging(const ArgsManager& args);
2425
} // namespace init
2526

2627
#endif // BITCOIN_INIT_COMMON_H

0 commit comments

Comments
 (0)