Merge bitcoin/bitcoin#33960: log: Use more severe log level (warn/err) where appropriate

fa45a1503e log: Use LogWarning for non-critical logs (MarcoFalke)
fa0018d011 log: Use LogError for fatal errors (MarcoFalke)
22229de728 doc: Fix typo in init log (MarcoFalke)

Pull request description:

  Logging supports severity levels above info via the legacy `LogPrintf`. So use the more appropriate `LogError` or `LogWarning`, where it applies.

  This has a few small benefits:

  * It often allows to remove the manual and literal "error: ", "Warning:", ... prefixes. Instead the uniform log level formatting is used.
  * It is easier to grep or glance for more severe logs, which indicate some kind of alert.
  * `LogPrintf` didn't indicate any severity level, but it is an alias for `LogInfo`. So having the log level explicitly spelled out makes it easier to read the code.
  * Also, remove the redundant trailing `\n` newline, while touching.
  * Also, remove the `__func__` formatting in the log string, which is redundant with `-logsourcelocations`. Instead, use a unique log string for each location.

ACKs for top commit:
  l0rinc:
    Code review ACK fa45a1503e
  stickies-v:
    ACK fa45a1503e
  rkrux:
    crACK fa45a1503e

Tree-SHA512: 516d439c36716f969c6e82d00bcda03c92c8765a9e41593b90052c86f8fa3a3dacbb2c3dc98bfc862cefa54cae34842b488671a20dd86cf1d15fb94aa5563406
This commit is contained in:
merge-script
2025-12-02 13:35:16 +00:00
29 changed files with 163 additions and 162 deletions

View File

@@ -198,7 +198,7 @@ static void RemovePidFile(const ArgsManager& args)
const auto pid_path{GetPidFile(args)};
if (std::error_code error; !fs::remove(pid_path, error)) {
std::string msg{error ? error.message() : "File does not exist"};
LogPrintf("Unable to remove PID file (%s): %s\n", fs::PathToString(pid_path), msg);
LogWarning("Unable to remove PID file (%s): %s", fs::PathToString(pid_path), msg);
}
}
@@ -1351,7 +1351,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
index->Interrupt();
index->Stop();
if (!(index->Init() && index->StartBackgroundSync())) {
LogPrintf("[snapshot] WARNING failed to restart index %s on snapshot chain\n", index->GetName());
LogWarning("[snapshot] Failed to restart index %s on snapshot chain", index->GetName());
}
}
};
@@ -1415,11 +1415,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// Warn about relative -datadir path.
if (args.IsArgSet("-datadir") && !args.GetPathArg("-datadir").is_absolute()) {
LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the "
"current working directory '%s'. This is fragile, because if bitcoin is started in the future "
"from a different location, it will be unable to locate the current data files. There could "
"also be data loss if bitcoin is started while in a temporary directory.\n",
args.GetArg("-datadir", ""), fs::PathToString(fs::current_path()));
LogWarning("Relative datadir option '%s' specified, which will be interpreted relative to the "
"current working directory '%s'. This is fragile, because if bitcoin is started in the future "
"from a different location, it will be unable to locate the current data files. There could "
"also be data loss if bitcoin is started while in a temporary directory.",
args.GetArg("-datadir", ""), fs::PathToString(fs::current_path()));
}
assert(!node.scheduler);
@@ -1881,7 +1881,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
} else {
// Prior to setting NODE_NETWORK, check if we can provide historical blocks.
if (!WITH_LOCK(chainman.GetMutex(), return chainman.BackgroundSyncInProgress())) {
LogInfo("Setting NODE_NETWORK on non-prune mode");
LogInfo("Setting NODE_NETWORK in non-prune mode");
g_local_services = ServiceFlags(g_local_services | NODE_NETWORK);
} else {
LogInfo("Running node in NODE_NETWORK_LIMITED mode until snapshot background sync completes");