Skip to content

Commit d4cc0c6

Browse files
committed
Merge bitcoin/bitcoin#30750: scripted-diff: LogPrint -> LogDebug
fa09cb4 refactor: Remove unused LogPrint (MarcoFalke) 3333415 scripted-diff: LogPrint -> LogDebug (MarcoFalke) Pull request description: `LogPrint` has many issues: * It seems to indicate that something is being "printed", however config options such as `-printtoconsole` actually control what and where something is logged. * It does not mention the log severity (debug). * It is a deprecated alias for `LogDebug`, according to the dev notes. * It wastes review cycles, because reviewers sometimes point out that it is deprecated. * It makes the code inconsistent, when both are used, possibly even in lines right next to each other (like in `InitHTTPServer`) Fix all issues by removing the deprecated alias. I checked all conflicting pull requests and at the time of writing there are no conflicts, except in pull requests that are marked as draft, are yet unreviewed, or are blocked on feedback for other reasons. So I think it is fine to do now. ACKs for top commit: stickies-v: ACK fa09cb4 danielabrozzoni: utACK fa09cb4 TheCharlatan: ACK fa09cb4 Tree-SHA512: 14270f4cfa3906025a0b994cbb5b2e3c8c2427c0beb19c717a505a2ccbfb1fd1ecf2fd03f6c52d22cde69a8d057e50d2207119fab2c2bc8228db3f10d4288d0f
2 parents ef6f49e + fa09cb4 commit d4cc0c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+361
-369
lines changed

contrib/devtools/bitcoin-tidy/example_logprintf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
2222
#define LogPrintLevel_(category, level, ...) LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
2323
#define LogPrintf(...) LogPrintLevel_(LogFlags::NONE, Level::None, __VA_ARGS__)
2424

25-
#define LogPrint(category, ...) \
25+
#define LogDebug(category, ...) \
2626
do { \
2727
LogPrintf(__VA_ARGS__); \
2828
} while (0)

doc/developer-notes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,6 @@ logging messages. They should be used as follows:
741741
useful for debugging and can reasonably be enabled on a production
742742
system (that has sufficient free storage space). They will be logged
743743
if the program is started with `-debug=category` or `-debug=1`.
744-
Note that `LogPrint(BCLog::CATEGORY, fmt, params...)` is a deprecated
745-
alias for `LogDebug`.
746744

747745
- `LogInfo(fmt, params...)` should only be used rarely, e.g. for startup
748746
messages or for infrequent and important events such as a new block tip

doc/fuzzing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ index 7601a6ea84..702d0f56ce 100644
257257
// Check start string, network magic
258258
- if (memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
259259
+ if (false && memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) { // skip network magic checking
260-
LogPrint(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id);
260+
LogDebug(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id);
261261
return -1;
262262
}
263263
@@ -788,7 +788,7 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
@@ -266,7 +266,7 @@ index 7601a6ea84..702d0f56ce 100644
266266
// Check checksum and header message type string
267267
- if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
268268
+ if (false && memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) { // skip checksum checking
269-
LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
269+
LogDebug(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
270270
SanitizeString(msg.m_type), msg.m_message_size,
271271
HexStr(Span{hash}.first(CMessageHeader::CHECKSUM_SIZE)),
272272
EOF

src/addrman.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void AddrManImpl::Unserialize(Stream& s_)
342342
serialized_asmap_checksum == supplied_asmap_checksum};
343343

344344
if (!restore_bucketing) {
345-
LogPrint(BCLog::ADDRMAN, "Bucketing method was updated, re-bucketing addrman entries from disk\n");
345+
LogDebug(BCLog::ADDRMAN, "Bucketing method was updated, re-bucketing addrman entries from disk\n");
346346
}
347347

348348
for (auto bucket_entry : bucket_entries) {
@@ -387,7 +387,7 @@ void AddrManImpl::Unserialize(Stream& s_)
387387
}
388388
}
389389
if (nLost + nLostUnk > 0) {
390-
LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
390+
LogDebug(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
391391
}
392392

393393
const int check_code{CheckAddrman()};
@@ -481,7 +481,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
481481
assert(infoDelete.nRefCount > 0);
482482
infoDelete.nRefCount--;
483483
vvNew[nUBucket][nUBucketPos] = -1;
484-
LogPrint(BCLog::ADDRMAN, "Removed %s from new[%i][%i]\n", infoDelete.ToStringAddrPort(), nUBucket, nUBucketPos);
484+
LogDebug(BCLog::ADDRMAN, "Removed %s from new[%i][%i]\n", infoDelete.ToStringAddrPort(), nUBucket, nUBucketPos);
485485
if (infoDelete.nRefCount == 0) {
486486
Delete(nIdDelete);
487487
}
@@ -536,7 +536,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
536536
vvNew[nUBucket][nUBucketPos] = nIdEvict;
537537
nNew++;
538538
m_network_counts[infoOld.GetNetwork()].n_new++;
539-
LogPrint(BCLog::ADDRMAN, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
539+
LogDebug(BCLog::ADDRMAN, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
540540
infoOld.ToStringAddrPort(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
541541
}
542542
assert(vvTried[nKBucket][nKBucketPos] == -1);
@@ -612,7 +612,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
612612
pinfo->nRefCount++;
613613
vvNew[nUBucket][nUBucketPos] = nId;
614614
const auto mapped_as{m_netgroupman.GetMappedAS(addr)};
615-
LogPrint(BCLog::ADDRMAN, "Added %s%s to new[%i][%i]\n",
615+
LogDebug(BCLog::ADDRMAN, "Added %s%s to new[%i][%i]\n",
616616
addr.ToStringAddrPort(), (mapped_as ? strprintf(" mapped to AS%i", mapped_as) : ""), nUBucket, nUBucketPos);
617617
} else {
618618
if (pinfo->nRefCount == 0) {
@@ -663,7 +663,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
663663
}
664664
// Output the entry we'd be colliding with, for debugging purposes
665665
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
666-
LogPrint(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
666+
LogDebug(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
667667
colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "",
668668
addr.ToStringAddrPort(),
669669
m_tried_collisions.size());
@@ -672,7 +672,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
672672
// move nId to the tried tables
673673
MakeTried(info, nId);
674674
const auto mapped_as{m_netgroupman.GetMappedAS(addr)};
675-
LogPrint(BCLog::ADDRMAN, "Moved %s%s to tried[%i][%i]\n",
675+
LogDebug(BCLog::ADDRMAN, "Moved %s%s to tried[%i][%i]\n",
676676
addr.ToStringAddrPort(), (mapped_as ? strprintf(" mapped to AS%i", mapped_as) : ""), tried_bucket, tried_bucket_pos);
677677
return true;
678678
}
@@ -685,7 +685,7 @@ bool AddrManImpl::Add_(const std::vector<CAddress>& vAddr, const CNetAddr& sourc
685685
added += AddSingle(*it, source, time_penalty) ? 1 : 0;
686686
}
687687
if (added > 0) {
688-
LogPrint(BCLog::ADDRMAN, "Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(), source.ToStringAddr(), nTried, nNew);
688+
LogDebug(BCLog::ADDRMAN, "Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(), source.ToStringAddr(), nTried, nNew);
689689
}
690690
return added > 0;
691691
}
@@ -777,7 +777,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option
777777

778778
// With probability GetChance() * chance_factor, return the entry.
779779
if (insecure_rand.randbits<30>() < chance_factor * info.GetChance() * (1 << 30)) {
780-
LogPrint(BCLog::ADDRMAN, "Selected %s from %s\n", info.ToStringAddrPort(), search_tried ? "tried" : "new");
780+
LogDebug(BCLog::ADDRMAN, "Selected %s from %s\n", info.ToStringAddrPort(), search_tried ? "tried" : "new");
781781
return {info, info.m_last_try};
782782
}
783783

@@ -837,7 +837,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
837837

838838
addresses.push_back(ai);
839839
}
840-
LogPrint(BCLog::ADDRMAN, "GetAddr returned %d random addresses\n", addresses.size());
840+
LogDebug(BCLog::ADDRMAN, "GetAddr returned %d random addresses\n", addresses.size());
841841
return addresses;
842842
}
843843

@@ -935,7 +935,7 @@ void AddrManImpl::ResolveCollisions_()
935935

936936
// Give address at least 60 seconds to successfully connect
937937
if (current_time - info_old.m_last_try > 60s) {
938-
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToStringAddrPort(), info_new.ToStringAddrPort());
938+
LogDebug(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToStringAddrPort(), info_new.ToStringAddrPort());
939939

940940
// Replaces an existing address already in the tried table with the new address
941941
Good_(info_new, false, current_time);
@@ -945,7 +945,7 @@ void AddrManImpl::ResolveCollisions_()
945945
// If the collision hasn't resolved in some reasonable amount of time,
946946
// just evict the old entry -- we must not be able to
947947
// connect to it for some reason.
948-
LogPrint(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToStringAddrPort(), info_new.ToStringAddrPort());
948+
LogDebug(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToStringAddrPort(), info_new.ToStringAddrPort());
949949
Good_(info_new, false, current_time);
950950
erase_collision = true;
951951
}

src/banman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void BanMan::LoadBanlist()
3636
if (m_ban_db.Read(m_banned)) {
3737
SweepBanned(); // sweep out unused entries
3838

39-
LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
39+
LogDebug(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
4040
Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
4141
} else {
4242
LogPrintf("Recreating the banlist database\n");
@@ -65,7 +65,7 @@ void BanMan::DumpBanlist()
6565
m_is_dirty = true;
6666
}
6767

68-
LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
68+
LogDebug(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
6969
Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
7070
}
7171

@@ -193,7 +193,7 @@ void BanMan::SweepBanned()
193193
m_banned.erase(it++);
194194
m_is_dirty = true;
195195
notify_ui = true;
196-
LogPrint(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
196+
LogDebug(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
197197
} else {
198198
++it;
199199
}

src/bench/logging.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// All but 2 of the benchmarks should have roughly similar performance:
1313
//
14-
// LogPrintWithoutCategory should be ~3 orders of magnitude faster, as nothing is logged.
14+
// LogWithoutDebug should be ~3 orders of magnitude faster, as nothing is logged.
1515
//
1616
// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids disk writes.
1717

@@ -40,14 +40,14 @@ static void LogPrintLevelWithoutThreadNames(benchmark::Bench& bench)
4040
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); });
4141
}
4242

43-
static void LogPrintWithCategory(benchmark::Bench& bench)
43+
static void LogWithDebug(benchmark::Bench& bench)
4444
{
45-
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogPrint(BCLog::NET, "%s\n", "test"); });
45+
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });
4646
}
4747

48-
static void LogPrintWithoutCategory(benchmark::Bench& bench)
48+
static void LogWithoutDebug(benchmark::Bench& bench)
4949
{
50-
Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogPrint(BCLog::NET, "%s\n", "test"); });
50+
Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });
5151
}
5252

5353
static void LogPrintfCategoryWithThreadNames(benchmark::Bench& bench)
@@ -79,14 +79,14 @@ static void LogWithoutWriteToFile(benchmark::Bench& bench)
7979
// Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`.
8080
Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {
8181
LogPrintf("%s\n", "test");
82-
LogPrint(BCLog::NET, "%s\n", "test");
82+
LogDebug(BCLog::NET, "%s\n", "test");
8383
});
8484
}
8585

8686
BENCHMARK(LogPrintLevelWithThreadNames, benchmark::PriorityLevel::HIGH);
8787
BENCHMARK(LogPrintLevelWithoutThreadNames, benchmark::PriorityLevel::HIGH);
88-
BENCHMARK(LogPrintWithCategory, benchmark::PriorityLevel::HIGH);
89-
BENCHMARK(LogPrintWithoutCategory, benchmark::PriorityLevel::HIGH);
88+
BENCHMARK(LogWithDebug, benchmark::PriorityLevel::HIGH);
89+
BENCHMARK(LogWithoutDebug, benchmark::PriorityLevel::HIGH);
9090
BENCHMARK(LogPrintfCategoryWithThreadNames, benchmark::PriorityLevel::HIGH);
9191
BENCHMARK(LogPrintfCategoryWithoutThreadNames, benchmark::PriorityLevel::HIGH);
9292
BENCHMARK(LogPrintfWithThreadNames, benchmark::PriorityLevel::HIGH);

src/blockencodings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
167167
break;
168168
}
169169

170-
LogPrint(BCLog::CMPCTBLOCK, "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), GetSerializeSize(cmpctblock));
170+
LogDebug(BCLog::CMPCTBLOCK, "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), GetSerializeSize(cmpctblock));
171171

172172
return READ_STATUS_OK;
173173
}
@@ -217,10 +217,10 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
217217
return READ_STATUS_CHECKBLOCK_FAILED;
218218
}
219219

220-
LogPrint(BCLog::CMPCTBLOCK, "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool (incl at least %lu from extra pool) and %lu txn requested\n", hash.ToString(), prefilled_count, mempool_count, extra_count, vtx_missing.size());
220+
LogDebug(BCLog::CMPCTBLOCK, "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool (incl at least %lu from extra pool) and %lu txn requested\n", hash.ToString(), prefilled_count, mempool_count, extra_count, vtx_missing.size());
221221
if (vtx_missing.size() < 5) {
222222
for (const auto& tx : vtx_missing) {
223-
LogPrint(BCLog::CMPCTBLOCK, "Reconstructed block %s required tx %s\n", hash.ToString(), tx->GetHash().ToString());
223+
LogDebug(BCLog::CMPCTBLOCK, "Reconstructed block %s required tx %s\n", hash.ToString(), tx->GetHash().ToString());
224224
}
225225
}
226226

src/dbwrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void SetMaxOpenFiles(leveldb::Options *options) {
130130
options->max_open_files = 64;
131131
}
132132
#endif
133-
LogPrint(BCLog::LEVELDB, "LevelDB using max_open_files=%d (default=%d)\n",
133+
LogDebug(BCLog::LEVELDB, "LevelDB using max_open_files=%d (default=%d)\n",
134134
options->max_open_files, default_open_files);
135135
}
136136

@@ -299,7 +299,7 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
299299
HandleError(status);
300300
if (log_memory) {
301301
double mem_after = DynamicMemoryUsage() / 1024.0 / 1024;
302-
LogPrint(BCLog::LEVELDB, "WriteBatch memory usage: db=%s, before=%.1fMiB, after=%.1fMiB\n",
302+
LogDebug(BCLog::LEVELDB, "WriteBatch memory usage: db=%s, before=%.1fMiB, after=%.1fMiB\n",
303303
m_name, mem_before, mem_after);
304304
}
305305
return true;
@@ -310,7 +310,7 @@ size_t CDBWrapper::DynamicMemoryUsage() const
310310
std::string memory;
311311
std::optional<size_t> parsed;
312312
if (!DBContext().pdb->GetProperty("leveldb.approximate-memory-usage", &memory) || !(parsed = ToIntegral<size_t>(memory))) {
313-
LogPrint(BCLog::LEVELDB, "Failed to get approximate-memory-usage property\n");
313+
LogDebug(BCLog::LEVELDB, "Failed to get approximate-memory-usage property\n");
314314
return 0;
315315
}
316316
return parsed.value();

src/flatfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_
6666
if (CheckDiskSpace(m_dir, inc_size)) {
6767
FILE *file = Open(pos);
6868
if (file) {
69-
LogPrint(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
69+
LogDebug(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
7070
AllocateFileRange(file, pos.nPos, inc_size);
7171
fclose(file);
7272
return inc_size;

0 commit comments

Comments
 (0)