Skip to content

Commit fbfa2e4

Browse files
committed
Merge #14057: [Logging] Only log "Using config file PATH_TO_bitcoin.conf" message on startup if conf file exists
946107a Only log "Using PATH_TO_bitcoin.conf" message on startup if conf file exists. (Alexander Leishman) Pull request description: Currently we log a message indicating that a bitcoin.conf file is being used even if one does not exist. This PR changes the logic to: **If config file does not exist and no -conf flag passed, log:** `Config file: FILE_PATH (not found, skipping)`. Where `FILE_PATH` is the default or the path passed in with the `-conf` flag. **If config file does not exist and -conf flag passed with incorrect path, log warning:** `Warning: The specified config file FILE_PATH does not exist` **If config file exists, log**: `Config file: FILE_PATH` Note: This is a (modified) subset of changes introduced in bitcoin/bitcoin#13761 which creates a default example config file. I think it makes sense to extract this small bit out into a separate PR. Tree-SHA512: be0f0ae6a0c9041e2d6acb54d2563bbcc79786fb2f8bf9a963fe01bc54cd4e388b89079fde1eb79f7f17099776428e5e984bf7107590a3d1ecfc0562dbc6e3f5
2 parents ae251fa + 946107a commit fbfa2e4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/init.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,19 @@ bool AppInitMain()
12451245
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
12461246
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
12471247
LogPrintf("Using data directory %s\n", GetDataDir().string());
1248-
LogPrintf("Using config file %s\n", GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)).string());
1248+
1249+
// Only log conf file usage message if conf file actually exists.
1250+
fs::path config_file_path = GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
1251+
if (fs::exists(config_file_path)) {
1252+
LogPrintf("Config file: %s\n", config_file_path.string());
1253+
} else if (gArgs.IsArgSet("-conf")) {
1254+
// Warn if no conf file exists at path provided by user
1255+
InitWarning(strprintf(_("The specified config file %s does not exist\n"), config_file_path.string()));
1256+
} else {
1257+
// Not categorizing as "Warning" because it's the default behavior
1258+
LogPrintf("Config file: %s (not found, skipping)\n", config_file_path.string());
1259+
}
1260+
12491261
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
12501262

12511263
// Warn about relative -datadir path.

0 commit comments

Comments
 (0)