mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
Move common logging start code to init/common
This commit is contained in:
parent
1fb7fcfa52
commit
5bed2ab42c
3 changed files with 41 additions and 30 deletions
33
src/init.cpp
33
src/init.cpp
|
@ -1122,37 +1122,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||
// Detailed error printed inside CreatePidFile().
|
||||
return false;
|
||||
}
|
||||
if (LogInstance().m_print_to_file) {
|
||||
if (args.GetBoolArg("-shrinkdebugfile", LogInstance().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
|
||||
LogInstance().ShrinkDebugFile();
|
||||
}
|
||||
if (!init::StartLogging(args)) {
|
||||
// Detailed error printed inside StartLogging().
|
||||
return false;
|
||||
}
|
||||
if (!LogInstance().StartLogging()) {
|
||||
return InitError(strprintf(Untranslated("Could not open debug log file %s"),
|
||||
LogInstance().m_file_path.string()));
|
||||
}
|
||||
|
||||
if (!LogInstance().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());
|
||||
|
||||
// Only log conf file usage message if conf file actually exists.
|
||||
fs::path config_file_path = GetConfigFile(args.GetArg("-conf", BITCOIN_CONF_FILENAME));
|
||||
if (fs::exists(config_file_path)) {
|
||||
LogPrintf("Config file: %s\n", config_file_path.string());
|
||||
} else if (args.IsArgSet("-conf")) {
|
||||
// Warn if no conf file exists at path provided by user
|
||||
InitWarning(strprintf(_("The specified config file %s does not exist"), config_file_path.string()));
|
||||
} else {
|
||||
// Not categorizing as "Warning" because it's the default behavior
|
||||
LogPrintf("Config file: %s (not found, skipping)\n", config_file_path.string());
|
||||
}
|
||||
|
||||
// Log the config arguments to debug.log
|
||||
args.LogArgs();
|
||||
|
||||
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
|
||||
|
||||
|
|
|
@ -115,4 +115,41 @@ void SetLoggingCategories(const ArgsManager& args)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool StartLogging(const ArgsManager& args)
|
||||
{
|
||||
if (LogInstance().m_print_to_file) {
|
||||
if (args.GetBoolArg("-shrinkdebugfile", LogInstance().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
|
||||
LogInstance().ShrinkDebugFile();
|
||||
}
|
||||
}
|
||||
if (!LogInstance().StartLogging()) {
|
||||
return InitError(strprintf(Untranslated("Could not open debug log file %s"),
|
||||
LogInstance().m_file_path.string()));
|
||||
}
|
||||
|
||||
if (!LogInstance().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());
|
||||
|
||||
// Only log conf file usage message if conf file actually exists.
|
||||
fs::path config_file_path = GetConfigFile(args.GetArg("-conf", BITCOIN_CONF_FILENAME));
|
||||
if (fs::exists(config_file_path)) {
|
||||
LogPrintf("Config file: %s\n", config_file_path.string());
|
||||
} else if (args.IsArgSet("-conf")) {
|
||||
// Warn if no conf file exists at path provided by user
|
||||
InitWarning(strprintf(_("The specified config file %s does not exist"), config_file_path.string()));
|
||||
} else {
|
||||
// Not categorizing as "Warning" because it's the default behavior
|
||||
LogPrintf("Config file: %s (not found, skipping)\n", config_file_path.string());
|
||||
}
|
||||
|
||||
// Log the config arguments to debug.log
|
||||
args.LogArgs();
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace init
|
||||
|
|
|
@ -21,6 +21,7 @@ bool SanityChecks();
|
|||
void AddLoggingArgs(ArgsManager& args);
|
||||
void SetLoggingOptions(const ArgsManager& args);
|
||||
void SetLoggingCategories(const ArgsManager& args);
|
||||
bool StartLogging(const ArgsManager& args);
|
||||
} // namespace init
|
||||
|
||||
#endif // BITCOIN_INIT_COMMON_H
|
||||
|
|
Loading…
Add table
Reference in a new issue