Skip to content

Commit 6cdc5a9

Browse files
committed
Merge bitcoin/bitcoin#32967: log: [refactor] Use info level for init logs
face812 log: [refactor] Use info level for init logs (MarcoFalke) fa18376 log: Remove function name from init logs (MarcoFalke) Pull request description: Many of the normal, and expected init logs, which are run once after startup use the deprecated alias of `LogInfo`. Fix that by using `LogInfo` directly, which is a refactor, except for a few log lines that also have `__func__` removed. (Also remove the unused trailing `\n` char while touching those logs) ACKs for top commit: stickies-v: re-ACK face812 fanquake: ACK face812 Tree-SHA512: 28c296129c9a31dff04f529c53db75057eae8a73fc7419e2f3068963dbb7b7fb9a457b2653f9120361fdb06ac97d1ee2be815c09ac659780dff01d7cd29f8480
2 parents 443c32a + face812 commit 6cdc5a9

28 files changed

+120
-115
lines changed

src/banman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void BanMan::LoadBanlist()
3939
LogDebug(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
4040
Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
4141
} else {
42-
LogPrintf("Recreating the banlist database\n");
42+
LogInfo("Recreating the banlist database");
4343
m_banned = {};
4444
m_is_dirty = true;
4545
}

src/chainparams.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti
9696
if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
9797
options.version_bits_parameters[Consensus::DeploymentPos(j)] = vbparams;
9898
found = true;
99-
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d\n", vDeploymentParams[0], vbparams.start_time, vbparams.timeout, vbparams.min_activation_height);
99+
LogInfo("Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d",
100+
vDeploymentParams[0], vbparams.start_time, vbparams.timeout, vbparams.min_activation_height);
100101
break;
101102
}
102103
}

src/dbwrapper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,25 +228,25 @@ CDBWrapper::CDBWrapper(const DBParams& params)
228228
DBContext().options.env = DBContext().penv;
229229
} else {
230230
if (params.wipe_data) {
231-
LogPrintf("Wiping LevelDB in %s\n", fs::PathToString(params.path));
231+
LogInfo("Wiping LevelDB in %s", fs::PathToString(params.path));
232232
leveldb::Status result = leveldb::DestroyDB(fs::PathToString(params.path), DBContext().options);
233233
HandleError(result);
234234
}
235235
TryCreateDirectories(params.path);
236-
LogPrintf("Opening LevelDB in %s\n", fs::PathToString(params.path));
236+
LogInfo("Opening LevelDB in %s", fs::PathToString(params.path));
237237
}
238238
// PathToString() return value is safe to pass to leveldb open function,
239239
// because on POSIX leveldb passes the byte string directly to ::open(), and
240240
// on Windows it converts from UTF-8 to UTF-16 before calling ::CreateFileW
241241
// (see env_posix.cc and env_windows.cc).
242242
leveldb::Status status = leveldb::DB::Open(DBContext().options, fs::PathToString(params.path), &DBContext().pdb);
243243
HandleError(status);
244-
LogPrintf("Opened LevelDB successfully\n");
244+
LogInfo("Opened LevelDB successfully");
245245

246246
if (params.options.force_compact) {
247-
LogPrintf("Starting database compaction of %s\n", fs::PathToString(params.path));
247+
LogInfo("Starting database compaction of %s", fs::PathToString(params.path));
248248
DBContext().pdb->CompactRange(nullptr, nullptr);
249-
LogPrintf("Finished database compaction of %s\n", fs::PathToString(params.path));
249+
LogInfo("Finished database compaction of %s", fs::PathToString(params.path));
250250
}
251251

252252
assert(!m_obfuscation); // Needed for unobfuscated Read()/Write() below

src/dummywallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DummyWalletInit : public WalletInitInterface {
2121
bool HasWalletSupport() const override {return false;}
2222
void AddWalletOptions(ArgsManager& argsman) const override;
2323
bool ParameterInteraction() const override {return true;}
24-
void Construct(node::NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
24+
void Construct(node::NodeContext& node) const override { LogInfo("No wallet support compiled in!"); }
2525
};
2626

2727
void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
391391

392392
// Bind addresses
393393
for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
394-
LogPrintf("Binding RPC on address %s port %i\n", i->first, i->second);
394+
LogInfo("Binding RPC on address %s port %i", i->first, i->second);
395395
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
396396
if (bind_handle) {
397397
const std::optional<CNetAddr> addr{LookupHost(i->first, false)};

src/init.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void Shutdown(NodeContext& node)
284284
static Mutex g_shutdown_mutex;
285285
TRY_LOCK(g_shutdown_mutex, lock_shutdown);
286286
if (!lock_shutdown) return;
287-
LogPrintf("%s: In progress...\n", __func__);
287+
LogInfo("Shutdown in progress...");
288288
Assert(node.args);
289289

290290
/// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
@@ -395,7 +395,7 @@ void Shutdown(NodeContext& node)
395395

396396
RemovePidFile(*node.args);
397397

398-
LogPrintf("%s: done\n", __func__);
398+
LogInfo("Shutdown done");
399399
}
400400

401401
/**
@@ -898,7 +898,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
898898
// on the command line or in this chain's section of the config file.
899899
ChainType chain = args.GetChainType();
900900
if (chain == ChainType::SIGNET) {
901-
LogPrintf("Signet derived magic (message start): %s\n", HexStr(chainparams.MessageStart()));
901+
LogInfo("Signet derived magic (message start): %s", HexStr(chainparams.MessageStart()));
902902
}
903903
bilingual_str errors;
904904
for (const auto& arg : args.GetUnsuitableSectionOnlyArgs()) {
@@ -1234,7 +1234,9 @@ static ChainstateLoadResult InitAndLoadChainstate(
12341234
if (!mempool_error.empty()) {
12351235
return {ChainstateLoadStatus::FAILURE_FATAL, mempool_error};
12361236
}
1237-
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", cache_sizes.coins * (1.0 / 1024 / 1024), mempool_opts.max_size_bytes * (1.0 / 1024 / 1024));
1237+
LogInfo("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)",
1238+
cache_sizes.coins * (1.0 / 1024 / 1024),
1239+
mempool_opts.max_size_bytes * (1.0 / 1024 / 1024));
12381240
ChainstateManager::Options chainman_opts{
12391241
.chainparams = chainparams,
12401242
.datadir = args.GetDataDirNet(),
@@ -1274,10 +1276,10 @@ static ChainstateLoadResult InitAndLoadChainstate(
12741276
// libbitcoinkernel.
12751277
chainman.snapshot_download_completed = [&node]() {
12761278
if (!node.chainman->m_blockman.IsPruneMode()) {
1277-
LogPrintf("[snapshot] re-enabling NODE_NETWORK services\n");
1279+
LogInfo("[snapshot] re-enabling NODE_NETWORK services");
12781280
node.connman->AddLocalServices(NODE_NETWORK);
12791281
}
1280-
LogPrintf("[snapshot] restarting indexes\n");
1282+
LogInfo("[snapshot] restarting indexes");
12811283
// Drain the validation interface queue to ensure that the old indexes
12821284
// don't have any pending work.
12831285
Assert(node.validation_signals)->SyncWithValidationInterfaceQueue();
@@ -1345,7 +1347,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13451347
return false;
13461348
}
13471349

1348-
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, available_fds);
1350+
LogInfo("Using at most %i automatic connections (%i file descriptors available)", nMaxConnections, available_fds);
13491351

13501352
// Warn about relative -datadir path.
13511353
if (args.IsArgSet("-datadir") && !args.GetPathArg("-datadir").is_absolute()) {
@@ -1402,7 +1404,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14021404
} catch (const std::exception& e) {
14031405
return InitError(Untranslated(strprintf("Unable to bind to IPC address '%s'. %s", address, e.what())));
14041406
}
1405-
LogPrintf("Listening for IPC requests on address %s\n", address);
1407+
LogInfo("Listening for IPC requests on address %s", address);
14061408
}
14071409
}
14081410

@@ -1495,9 +1497,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14951497
return false;
14961498
}
14971499
const uint256 asmap_version = (HashWriter{} << asmap).GetHash();
1498-
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
1500+
LogInfo("Using asmap version %s for IP bucketing", asmap_version.ToString());
14991501
} else {
1500-
LogPrintf("Using /16 prefix for IP bucketing\n");
1502+
LogInfo("Using /16 prefix for IP bucketing");
15011503
}
15021504

15031505
// Initialize netgroup manager
@@ -1753,7 +1755,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17531755
// As LoadBlockIndex can take several minutes, it's possible the user
17541756
// requested to kill the GUI during the last operation. If so, exit.
17551757
if (ShutdownRequested(node)) {
1756-
LogPrintf("Shutdown requested. Exiting.\n");
1758+
LogInfo("Shutdown requested. Exiting.");
17571759
return false;
17581760
}
17591761

@@ -1808,10 +1810,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18081810
} else {
18091811
// Prior to setting NODE_NETWORK, check if we can provide historical blocks.
18101812
if (!WITH_LOCK(chainman.GetMutex(), return chainman.BackgroundSyncInProgress())) {
1811-
LogPrintf("Setting NODE_NETWORK on non-prune mode\n");
1813+
LogInfo("Setting NODE_NETWORK on non-prune mode");
18121814
g_local_services = ServiceFlags(g_local_services | NODE_NETWORK);
18131815
} else {
1814-
LogPrintf("Running node in NODE_NETWORK_LIMITED mode until snapshot background sync completes\n");
1816+
LogInfo("Running node in NODE_NETWORK_LIMITED mode until snapshot background sync completes");
18151817
}
18161818
}
18171819

@@ -1870,7 +1872,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18701872
// Import blocks and ActivateBestChain()
18711873
ImportBlocks(chainman, vImportFiles);
18721874
if (args.GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
1873-
LogPrintf("Stopping after block import\n");
1875+
LogInfo("Stopping after block import");
18741876
if (!(Assert(node.shutdown_request))()) {
18751877
LogError("Failed to send shutdown signal after finishing block import\n");
18761878
}
@@ -1918,7 +1920,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
19181920
{
19191921
LOCK(chainman.GetMutex());
19201922
const auto& tip{*Assert(chainman.ActiveTip())};
1921-
LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
1923+
LogInfo("block tree size = %u", chainman.BlockIndex().size());
19221924
chain_active_height = tip.nHeight;
19231925
best_block_time = tip.GetBlockTime();
19241926
if (tip_info) {
@@ -1931,7 +1933,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
19311933
tip_info->header_time = chainman.m_best_header->GetBlockTime();
19321934
}
19331935
}
1934-
LogPrintf("nBestHeight = %d\n", chain_active_height);
1936+
LogInfo("nBestHeight = %d", chain_active_height);
19351937
if (node.peerman) node.peerman->SetBestBlock(chain_active_height, std::chrono::seconds{best_block_time});
19361938

19371939
// Map ports with NAT-PMP
@@ -2061,11 +2063,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
20612063
connOptions.m_specified_outgoing = connect;
20622064
}
20632065
if (!connOptions.m_specified_outgoing.empty() && !connOptions.vSeedNodes.empty()) {
2064-
LogPrintf("-seednode is ignored when -connect is used\n");
2066+
LogInfo("-seednode is ignored when -connect is used");
20652067
}
20662068

20672069
if (args.IsArgSet("-dnsseed") && args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED) && args.IsArgSet("-proxy")) {
2068-
LogPrintf("-dnsseed is ignored when -connect is used and -proxy is specified\n");
2070+
LogInfo("-dnsseed is ignored when -connect is used and -proxy is specified");
20692071
}
20702072
}
20712073

src/init/common.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ bool StartLogging(const ArgsManager& args)
114114
fs::PathToString(LogInstance().m_file_path))));
115115
}
116116

117-
if (!LogInstance().m_log_timestamps)
118-
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
119-
LogPrintf("Default data directory %s\n", fs::PathToString(GetDefaultDataDir()));
120-
LogPrintf("Using data directory %s\n", fs::PathToString(gArgs.GetDataDirNet()));
117+
if (!LogInstance().m_log_timestamps) {
118+
LogInfo("Startup time: %s", FormatISO8601DateTime(GetTime()));
119+
}
120+
LogInfo("Default data directory %s", fs::PathToString(GetDefaultDataDir()));
121+
LogInfo("Using data directory %s", fs::PathToString(gArgs.GetDataDirNet()));
121122

122123
// Only log conf file usage message if conf file actually exists.
123124
fs::path config_file_path = args.GetConfigFilePath();
@@ -126,12 +127,12 @@ bool StartLogging(const ArgsManager& args)
126127
} else if (fs::is_directory(config_file_path)) {
127128
LogWarning("Config file: %s (is directory, not file)", fs::PathToString(config_file_path));
128129
} else if (fs::exists(config_file_path)) {
129-
LogPrintf("Config file: %s\n", fs::PathToString(config_file_path));
130+
LogInfo("Config file: %s", fs::PathToString(config_file_path));
130131
} else if (args.IsArgSet("-conf")) {
131132
InitWarning(strprintf(_("The specified config file %s does not exist"), fs::PathToString(config_file_path)));
132133
} else {
133134
// Not categorizing as "Warning" because it's the default behavior
134-
LogPrintf("Config file: %s (not found, skipping)\n", fs::PathToString(config_file_path));
135+
LogInfo("Config file: %s (not found, skipping)", fs::PathToString(config_file_path));
135136
}
136137

137138
// Log the config arguments to debug.log
@@ -148,6 +149,6 @@ void LogPackageVersion()
148149
#else
149150
version_string += " (release build)";
150151
#endif
151-
LogPrintf(CLIENT_NAME " version %s\n", version_string);
152+
LogInfo(CLIENT_NAME " version %s", version_string);
152153
}
153154
} // namespace init

src/kernel/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ class SigNetParams : public CChainParams {
423423
0,
424424
0,
425425
};
426-
LogPrintf("Signet with challenge %s\n", HexStr(bin));
426+
LogInfo("Signet with challenge %s", HexStr(bin));
427427
}
428428

429429
if (options.seeds) {

src/node/blockstorage.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void BlockManager::FindFilesToPruneManual(
298298
setFilesToPrune.insert(fileNumber);
299299
count++;
300300
}
301-
LogPrintf("[%s] Prune (Manual): prune_height=%d removed %d blk/rev pairs\n",
301+
LogInfo("[%s] Prune (Manual): prune_height=%d removed %d blk/rev pairs",
302302
chain.GetRole(), last_block_can_prune, count);
303303
}
304304

@@ -418,7 +418,7 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
418418
// to disk, we must bootstrap the value for assumedvalid chainstates
419419
// from the hardcoded assumeutxo chainparams.
420420
base->m_chain_tx_count = au_data.m_chain_tx_count;
421-
LogPrintf("[snapshot] set m_chain_tx_count=%d for %s\n", au_data.m_chain_tx_count, snapshot_blockhash->ToString());
421+
LogInfo("[snapshot] set m_chain_tx_count=%d for %s", au_data.m_chain_tx_count, snapshot_blockhash->ToString());
422422
} else {
423423
// If this isn't called with a snapshot blockhash, make sure the cached snapshot height
424424
// is null. This is relevant during snapshot completion, when the blockman may be loaded
@@ -508,11 +508,11 @@ bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_block
508508
// Load block file info
509509
m_block_tree_db->ReadLastBlockFile(max_blockfile_num);
510510
m_blockfile_info.resize(max_blockfile_num + 1);
511-
LogPrintf("%s: last block file = %i\n", __func__, max_blockfile_num);
511+
LogInfo("Loading block index db: last block file = %i", max_blockfile_num);
512512
for (int nFile = 0; nFile <= max_blockfile_num; nFile++) {
513513
m_block_tree_db->ReadBlockFileInfo(nFile, m_blockfile_info[nFile]);
514514
}
515-
LogPrintf("%s: last block file info: %s\n", __func__, m_blockfile_info[max_blockfile_num].ToString());
515+
LogInfo("Loading block index db: last block file info: %s", m_blockfile_info[max_blockfile_num].ToString());
516516
for (int nFile = max_blockfile_num + 1; true; nFile++) {
517517
CBlockFileInfo info;
518518
if (m_block_tree_db->ReadBlockFileInfo(nFile, info)) {
@@ -523,7 +523,7 @@ bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_block
523523
}
524524

525525
// Check presence of blk files
526-
LogPrintf("Checking all blk files are present...\n");
526+
LogInfo("Checking all blk files are present...");
527527
std::set<int> setBlkDataFiles;
528528
for (const auto& [_, block_index] : m_block_index) {
529529
if (block_index.nStatus & BLOCK_HAVE_DATA) {
@@ -549,7 +549,7 @@ bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_block
549549
// Check whether we have ever pruned block & undo files
550550
m_block_tree_db->ReadFlag("prunedblockfiles", m_have_pruned);
551551
if (m_have_pruned) {
552-
LogPrintf("LoadBlockIndexDB(): Block files have previously been pruned\n");
552+
LogInfo("Loading block index db: Block files have previously been pruned");
553553
}
554554

555555
// Check whether we need to continue reindexing
@@ -622,7 +622,7 @@ void BlockManager::CleanupBlockRevFiles() const
622622
// Glob all blk?????.dat and rev?????.dat files from the blocks directory.
623623
// Remove the rev files immediately and insert the blk file paths into an
624624
// ordered map keyed by block file index.
625-
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
625+
LogInfo("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune");
626626
for (fs::directory_iterator it(m_opts.blocks_dir); it != fs::directory_iterator(); it++) {
627627
const std::string path = fs::PathToString(it->path().filename());
628628
if (fs::is_regular_file(*it) &&
@@ -1233,17 +1233,17 @@ void ImportBlocks(ChainstateManager& chainman, std::span<const fs::path> import_
12331233
if (file.IsNull()) {
12341234
break; // This error is logged in OpenBlockFile
12351235
}
1236-
LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
1236+
LogInfo("Reindexing block file blk%05u.dat...", (unsigned int)nFile);
12371237
chainman.LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
12381238
if (chainman.m_interrupt) {
1239-
LogPrintf("Interrupt requested. Exit %s\n", __func__);
1239+
LogInfo("Interrupt requested. Exit reindexing.");
12401240
return;
12411241
}
12421242
nFile++;
12431243
}
12441244
WITH_LOCK(::cs_main, chainman.m_blockman.m_block_tree_db->WriteReindexing(false));
12451245
chainman.m_blockman.m_blockfiles_indexed = true;
1246-
LogPrintf("Reindexing finished\n");
1246+
LogInfo("Reindexing finished");
12471247
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
12481248
chainman.ActiveChainstate().LoadGenesisBlock();
12491249
}
@@ -1252,10 +1252,10 @@ void ImportBlocks(ChainstateManager& chainman, std::span<const fs::path> import_
12521252
for (const fs::path& path : import_paths) {
12531253
AutoFile file{fsbridge::fopen(path, "rb")};
12541254
if (!file.IsNull()) {
1255-
LogPrintf("Importing blocks file %s...\n", fs::PathToString(path));
1255+
LogInfo("Importing blocks file %s...", fs::PathToString(path));
12561256
chainman.LoadExternalBlockFile(file);
12571257
if (chainman.m_interrupt) {
1258-
LogPrintf("Interrupt requested. Exit %s\n", __func__);
1258+
LogInfo("Interrupt requested. Exit block importing.");
12591259
return;
12601260
}
12611261
} else {

0 commit comments

Comments
 (0)