Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f6dc368
logging: simplify BCLog::Level enum class and LogLevelToStr() function
jonatack May 31, 2022
a2e089c
logging: add -loglevel configuration option
klementtan Jun 6, 2022
f036d99
doc: release note for -loglevel configuration option
klementtan Jun 8, 2022
4a2c0d0
logging, test: add BCLog::Level::Trace log severity level
jonatack Jun 1, 2022
361f186
logging: print wallet name more clearly to distinguish from category/…
jonatack Jul 7, 2022
118c756
logging: unconditionally log Info severity level messages
jonatack Jun 13, 2022
ce3e64c
refactor: replace hardcoded LogLevelsList vector with a programmatic one
jonatack Jun 13, 2022
df84a4f
refactor: use std::optional for GetLogCategory()
jonatack Jun 13, 2022
74bacb3
refactor: deduplicate LogCategory code
klementtan Jun 2, 2022
dd20c44
tor: log messages from torcontrol with category and debug level
jonatack May 25, 2022
fc0a50e
i2p: log messages from I2P with category and debug level
jonatack May 25, 2022
43315a0
refactor: remove unused i2p::Session::Log() template method
jonatack May 25, 2022
a0be62c
netbase: log netbase messages with category and debug level
jonatack May 25, 2022
844290b
net_processing: replace LogPrintf messages with category and debug level
jonatack May 31, 2022
8248529
net_processing: use severity-based logging for LogPrint messages
jonatack May 31, 2022
a22b1a3
net: replace LogPrintf messages with category and debug level
jonatack Jun 2, 2022
0d039f0
net, timedata: use severity-based logging for LogPrint messages
jonatack May 31, 2022
1116d90
logging: replace LogPrintf ADDRMAN messages with category and debug l…
jonatack Jul 6, 2022
e97f166
logging: use severity-based logging for LogPrint ADDRMAN messages
jonatack Jul 6, 2022
dc13d42
logging: replace mempool LogPrintf messages with category and debug l…
jonatack Jul 20, 2022
5db4361
logging: replace MEMPOOL LogPrint messages with category and debug level
jonatack Jul 7, 2022
10461c5
doc: update logging in fuzzing.md Honggfuzz code
jonatack Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ index cf987b699..636a4176a 100644
// Check start string, network magic
- if (memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
+ if (false && memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) { // skip network magic checking
LogPrint(BCLog::NET, "HEADER ERROR - MESSAGESTART (%s, %u bytes), received %s, peer=%d\n", hdr.GetCommand(), hdr.nMessageSize, HexStr(hdr.pchMessageStart), m_node_id);
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "HEADER ERROR - MESSAGESTART (%s, %u bytes), received %s, peer=%d\n", hdr.GetCommand(), hdr.nMessageSize, HexStr(hdr.pchMessageStart), m_node_id);
return -1;
}
@@ -768,7 +768,7 @@ Optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono::mic
Expand All @@ -254,7 +254,7 @@ index cf987b699..636a4176a 100644
// Check checksum and header command string
- if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
+ if (false && memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) { // skip checksum checking
LogPrint(BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s, peer=%d\n",
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s, peer=%d\n",
SanitizeString(msg->m_command), msg->m_message_size,
HexStr(Span<uint8_t>(hash.begin(), hash.begin() + CMessageHeader::CHECKSUM_SIZE)),
EOF
Expand Down
3 changes: 3 additions & 0 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ New settings
Tools and Utilities
-------------------

- A new `-loglevel` configuration option allows setting global and per-category
log severity levels. (#25203)

Wallet
------

Expand Down
14 changes: 7 additions & 7 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool CBanDB::Write(const banmap_t& banSet)
bool CBanDB::Read(banmap_t& banSet)
{
if (fs::exists(m_banlist_dat)) {
LogPrintf("banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.\n", fs::quoted(fs::PathToString(m_banlist_dat)));
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Warning, "banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.\n", fs::quoted(fs::PathToString(m_banlist_dat)));
}
// If the JSON banlist does not exist, then recreate it
if (!fs::exists(m_banlist_json)) {
Expand All @@ -156,15 +156,15 @@ bool CBanDB::Read(banmap_t& banSet)

if (!util::ReadSettings(m_banlist_json, settings, errors)) {
for (const auto& err : errors) {
LogPrintf("Cannot load banlist %s: %s\n", fs::PathToString(m_banlist_json), err);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Error, "Cannot load banlist %s: %s\n", fs::PathToString(m_banlist_json), err);
}
return false;
}

try {
BanMapFromJson(settings[JSON_KEY], banSet);
} catch (const std::runtime_error& e) {
LogPrintf("Cannot parse banlist %s: %s\n", fs::PathToString(m_banlist_json), e.what());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Error, "Cannot parse banlist %s: %s\n", fs::PathToString(m_banlist_json), e.what());
return false;
}

Expand All @@ -191,11 +191,11 @@ std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, con
const auto path_addr{args.GetDataDirNet() / "peers.dat"};
try {
DeserializeFileDB(path_addr, *addrman, CLIENT_VERSION);
LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman->size(), GetTimeMillis() - nStart);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Info, "Loaded %i addresses from peers.dat %dms\n", addrman->size(), GetTimeMillis() - nStart);
} catch (const DbNotFoundError&) {
// Addrman can be in an inconsistent state after failure, reset it
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
LogPrintf("Creating peers.dat because the file was not found (%s)\n", fs::quoted(fs::PathToString(path_addr)));
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Info, "Creating peers.dat because the file was not found (%s)\n", fs::quoted(fs::PathToString(path_addr)));
DumpPeerAddresses(args, *addrman);
} catch (const InvalidAddrManVersionError&) {
if (!RenameOver(path_addr, (fs::path)path_addr + ".bak")) {
Expand All @@ -204,7 +204,7 @@ std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, con
}
// Addrman can be in an inconsistent state after failure, reset it
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
LogPrintf("Creating new peers.dat because the file version was not compatible (%s). Original backed up to peers.dat.bak\n", fs::quoted(fs::PathToString(path_addr)));
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Warning, "Creating new peers.dat because the file version was not compatible (%s). Original backed up to peers.dat.bak\n", fs::quoted(fs::PathToString(path_addr)));
DumpPeerAddresses(args, *addrman);
} catch (const std::exception& e) {
addrman = nullptr;
Expand All @@ -225,7 +225,7 @@ std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path)
std::vector<CAddress> anchors;
try {
DeserializeFileDB(anchors_db_path, anchors, CLIENT_VERSION | ADDRV2_FORMAT);
LogPrintf("Loaded %i addresses from %s\n", anchors.size(), fs::quoted(fs::PathToString(anchors_db_path.filename())));
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Info, "Loaded %i addresses from %s\n", anchors.size(), fs::quoted(fs::PathToString(anchors_db_path.filename())));
} catch (const std::exception&) {
anchors.clear();
}
Expand Down
40 changes: 20 additions & 20 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void AddrManImpl::Unserialize(Stream& s_)
serialized_asmap_checksum == supplied_asmap_checksum};

if (!restore_bucketing) {
LogPrint(BCLog::ADDRMAN, "Bucketing method was updated, re-bucketing addrman entries from disk\n");
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Bucketing method was updated, re-bucketing addrman entries from disk\n");
}

for (auto bucket_entry : bucket_entries) {
Expand Down Expand Up @@ -387,7 +387,7 @@ void AddrManImpl::Unserialize(Stream& s_)
}
}
if (nLost + nLostUnk > 0) {
LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
}

const int check_code{CheckAddrman()};
Expand Down Expand Up @@ -478,7 +478,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
assert(infoDelete.nRefCount > 0);
infoDelete.nRefCount--;
vvNew[nUBucket][nUBucketPos] = -1;
LogPrint(BCLog::ADDRMAN, "Removed %s from new[%i][%i]\n", infoDelete.ToString(), nUBucket, nUBucketPos);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Removed %s from new[%i][%i]\n", infoDelete.ToString(), nUBucket, nUBucketPos);
if (infoDelete.nRefCount == 0) {
Delete(nIdDelete);
}
Expand Down Expand Up @@ -530,8 +530,8 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
infoOld.nRefCount = 1;
vvNew[nUBucket][nUBucketPos] = nIdEvict;
nNew++;
LogPrint(BCLog::ADDRMAN, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
infoOld.ToString(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
infoOld.ToString(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
}
assert(vvTried[nKBucket][nKBucketPos] == -1);

Expand Down Expand Up @@ -606,8 +606,8 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
ClearNew(nUBucket, nUBucketPos);
pinfo->nRefCount++;
vvNew[nUBucket][nUBucketPos] = nId;
LogPrint(BCLog::ADDRMAN, "Added %s mapped to AS%i to new[%i][%i]\n",
addr.ToString(), m_netgroupman.GetMappedAS(addr), nUBucket, nUBucketPos);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Added %s mapped to AS%i to new[%i][%i]\n",
addr.ToString(), m_netgroupman.GetMappedAS(addr), nUBucket, nUBucketPos);
} else {
if (pinfo->nRefCount == 0) {
Delete(nId);
Expand Down Expand Up @@ -657,16 +657,16 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
}
// Output the entry we'd be colliding with, for debugging purposes
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
LogPrint(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "",
addr.ToString(),
m_tried_collisions.size());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "",
addr.ToString(),
m_tried_collisions.size());
return false;
} else {
// move nId to the tried tables
MakeTried(info, nId);
LogPrint(BCLog::ADDRMAN, "Moved %s mapped to AS%i to tried[%i][%i]\n",
addr.ToString(), m_netgroupman.GetMappedAS(addr), tried_bucket, tried_bucket_pos);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Moved %s mapped to AS%i to tried[%i][%i]\n",
addr.ToString(), m_netgroupman.GetMappedAS(addr), tried_bucket, tried_bucket_pos);
return true;
}
}
Expand All @@ -678,7 +678,7 @@ bool AddrManImpl::Add_(const std::vector<CAddress> &vAddr, const CNetAddr& sourc
added += AddSingle(*it, source, nTimePenalty) ? 1 : 0;
}
if (added > 0) {
LogPrint(BCLog::ADDRMAN, "Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(), source.ToString(), nTried, nNew);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(), source.ToString(), nTried, nNew);
}
return added > 0;
}
Expand Down Expand Up @@ -735,7 +735,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
const AddrInfo& info{it_found->second};
// With probability GetChance() * fChanceFactor, return the entry.
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
LogPrint(BCLog::ADDRMAN, "Selected %s from tried\n", info.ToString());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Selected %s from tried\n", info.ToString());
return {info, info.nLastTry};
}
// Otherwise start over with a (likely) different bucket, and increased chance factor.
Expand Down Expand Up @@ -763,7 +763,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
const AddrInfo& info{it_found->second};
// With probability GetChance() * fChanceFactor, return the entry.
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
LogPrint(BCLog::ADDRMAN, "Selected %s from new\n", info.ToString());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Selected %s from new\n", info.ToString());
return {info, info.nLastTry};
}
// Otherwise start over with a (likely) different bucket, and increased chance factor.
Expand Down Expand Up @@ -806,7 +806,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct

addresses.push_back(ai);
}
LogPrint(BCLog::ADDRMAN, "GetAddr returned %d random addresses\n", addresses.size());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "GetAddr returned %d random addresses\n", addresses.size());
return addresses;
}

Expand Down Expand Up @@ -879,7 +879,7 @@ void AddrManImpl::ResolveCollisions_()

// Give address at least 60 seconds to successfully connect
if (current_time - info_old.nLastTry > 60) {
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToString(), info_new.ToString());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Replacing %s with %s in tried table\n", info_old.ToString(), info_new.ToString());

// Replaces an existing address already in the tried table with the new address
Good_(info_new, false, current_time);
Expand All @@ -889,7 +889,7 @@ void AddrManImpl::ResolveCollisions_()
// If the collision hasn't resolved in some reasonable amount of time,
// just evict the old entry -- we must not be able to
// connect to it for some reason.
LogPrint(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToString(), info_new.ToString());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToString(), info_new.ToString());
Good_(info_new, false, current_time);
erase_collision = true;
}
Expand Down Expand Up @@ -968,7 +968,7 @@ void AddrManImpl::Check() const

const int err{CheckAddrman()};
if (err) {
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Error, "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
assert(false);
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ void BanMan::LoadBanlist()
if (m_ban_db.Read(m_banned)) {
SweepBanned(); // sweep out unused entries

LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
GetTimeMillis() - n_start);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(), GetTimeMillis() - n_start);
} else {
LogPrintf("Recreating the banlist database\n");
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Info, "Recreating the banlist database\n");
m_banned = {};
m_is_dirty = true;
}
Expand All @@ -63,8 +62,7 @@ void BanMan::DumpBanlist()
SetBannedSetDirty(true);
}

LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
GetTimeMillis() - n_start);
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(), GetTimeMillis() - n_start);
}

void BanMan::ClearBanned()
Expand Down Expand Up @@ -191,7 +189,7 @@ void BanMan::SweepBanned()
m_banned.erase(it++);
m_is_dirty = true;
notify_ui = true;
LogPrint(BCLog::NET, "Removed banned node address/subnet: %s\n", sub_net.ToString());
LogPrintLevel(BCLog::ADDRMAN, BCLog::Level::Debug, "Removed banned node address/subnet: %s\n", sub_net.ToString());
} else {
++it;
}
Expand Down
24 changes: 9 additions & 15 deletions src/i2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool Session::Listen(Connection& conn)
conn.sock = StreamAccept();
return true;
} catch (const std::runtime_error& e) {
Log("Error listening: %s", e.what());
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error listening: %s\n", e.what());
CheckControlSock();
}
return false;
Expand Down Expand Up @@ -163,7 +163,7 @@ bool Session::Accept(Connection& conn)
return true;
}
} catch (const std::runtime_error& e) {
Log("Error accepting: %s", e.what());
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error accepting: %s\n", e.what());
CheckControlSock();
}
return false;
Expand Down Expand Up @@ -221,7 +221,7 @@ bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)

throw std::runtime_error(strprintf("\"%s\"", connect_reply.full));
} catch (const std::runtime_error& e) {
Log("Error connecting to %s: %s", to.ToString(), e.what());
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error connecting to %s: %s\n", to.ToString(), e.what());
CheckControlSock();
return false;
}
Expand All @@ -239,12 +239,6 @@ std::string Session::Reply::Get(const std::string& key) const
return pos->second.value();
}

template <typename... Args>
void Session::Log(const std::string& fmt, const Args&... args) const
{
LogPrint(BCLog::I2P, "%s\n", tfm::format(fmt, args...));
}

Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
const std::string& request,
bool check_result_ok) const
Expand Down Expand Up @@ -304,7 +298,7 @@ void Session::CheckControlSock()

std::string errmsg;
if (!m_control_sock->IsConnected(errmsg)) {
Log("Control socket error: %s", errmsg);
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Control socket error: %s\n", errmsg);
Disconnect();
}
}
Expand Down Expand Up @@ -355,7 +349,7 @@ void Session::CreateIfNotCreatedAlready()
return;
}

Log("Creating SAM session with %s", m_control_host.ToString());
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Creating SAM session with %s\n", m_control_host.ToString());

auto sock = Hello();

Expand All @@ -376,8 +370,8 @@ void Session::CreateIfNotCreatedAlready()
m_session_id = session_id;
m_control_sock = std::move(sock);

LogPrintfCategory(BCLog::I2P, "SAM session created: session id=%s, my address=%s\n",
m_session_id, m_my_addr.ToString());
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "SAM session created: session id=%s, my address=%s\n",
m_session_id, m_my_addr.ToString());
}

std::unique_ptr<Sock> Session::StreamAccept()
Expand Down Expand Up @@ -405,9 +399,9 @@ void Session::Disconnect()
{
if (m_control_sock->Get() != INVALID_SOCKET) {
if (m_session_id.empty()) {
Log("Destroying incomplete session");
LogPrintLevel(BCLog::I2P, BCLog::Level::Warning, "Destroying incomplete session\n");
} else {
Log("Destroying session %s", m_session_id);
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "Destroying session %s\n", m_session_id);
}
}
m_control_sock = std::make_unique<Sock>(INVALID_SOCKET);
Expand Down
8 changes: 0 additions & 8 deletions src/i2p.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ class Session
std::string Get(const std::string& key) const;
};

/**
* Log a message in the `BCLog::I2P` category.
* @param[in] fmt printf(3)-like format string.
* @param[in] args printf(3)-like arguments that correspond to `fmt`.
*/
template <typename... Args>
void Log(const std::string& fmt, const Args&... args) const;

/**
* Send request and get a reply from the SAM proxy.
* @param[in] sock A socket that is connected to the SAM proxy.
Expand Down
Loading