refactor(logging): use JLOG directly in Manifest.cpp for correct line numbers

- Replace logMftAct template functions with macros to preserve call site line numbers
- Use do-while(0) pattern to avoid dangling else warnings
- Add #undef at end of file to prevent namespace pollution
- Maintains exact same log format while fixing line number attribution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Nicholas Dudfield
2025-07-26 11:52:19 +07:00
parent d2098e9429
commit 640b9c91f9

View File

@@ -156,34 +156,22 @@ deserializeManifest(Slice s, beast::Journal journal)
} }
} }
template <class Stream> // Helper macros to format manifest log messages while preserving line numbers
Stream& #define LOG_MANIFEST_ACTION(stream, action, pk, seq) \
logMftAct( do \
Stream& s, { \
std::string const& action, JLOG(stream) << "Manifest: " << action \
PublicKey const& pk, << ";Pk: " << toBase58(TokenType::NodePublic, pk) \
std::uint32_t seq) << ";Seq: " << seq << ";"; \
{ } while (0)
s << "Manifest: " << action
<< ";Pk: " << toBase58(TokenType::NodePublic, pk) << ";Seq: " << seq
<< ";";
return s;
}
template <class Stream> #define LOG_MANIFEST_ACTION_WITH_OLD(stream, action, pk, seq, oldSeq) \
Stream& do \
logMftAct( { \
Stream& s, JLOG(stream) << "Manifest: " << action \
std::string const& action, << ";Pk: " << toBase58(TokenType::NodePublic, pk) \
PublicKey const& pk, << ";Seq: " << seq << ";OldSeq: " << oldSeq << ";"; \
std::uint32_t seq, } while (0)
std::uint32_t oldSeq)
{
s << "Manifest: " << action
<< ";Pk: " << toBase58(TokenType::NodePublic, pk) << ";Seq: " << seq
<< ";OldSeq: " << oldSeq << ";";
return s;
}
bool bool
Manifest::verify() const Manifest::verify() const
@@ -381,7 +369,7 @@ ManifestCache::applyManifest(Manifest m)
// several cases including when we receive manifests from a peer who // several cases including when we receive manifests from a peer who
// doesn't have the latest data. // doesn't have the latest data.
if (auto stream = j_.debug()) if (auto stream = j_.debug())
logMftAct( LOG_MANIFEST_ACTION_WITH_OLD(
stream, stream,
"Stale", "Stale",
m.masterKey, m.masterKey,
@@ -393,7 +381,7 @@ ManifestCache::applyManifest(Manifest m)
if (checkSignature && !m.verify()) if (checkSignature && !m.verify())
{ {
if (auto stream = j_.warn()) if (auto stream = j_.warn())
logMftAct(stream, "Invalid", m.masterKey, m.sequence); LOG_MANIFEST_ACTION(stream, "Invalid", m.masterKey, m.sequence);
return ManifestDisposition::invalid; return ManifestDisposition::invalid;
} }
@@ -407,7 +395,7 @@ ManifestCache::applyManifest(Manifest m)
bool const revoked = m.revoked(); bool const revoked = m.revoked();
if (auto stream = j_.warn(); stream && revoked) if (auto stream = j_.warn(); stream && revoked)
logMftAct(stream, "Revoked", m.masterKey, m.sequence); LOG_MANIFEST_ACTION(stream, "Revoked", m.masterKey, m.sequence);
// Sanity check: the master key of this manifest should not be used as // Sanity check: the master key of this manifest should not be used as
// the ephemeral key of another manifest: // the ephemeral key of another manifest:
@@ -476,7 +464,7 @@ ManifestCache::applyManifest(Manifest m)
if (iter == map_.end()) if (iter == map_.end())
{ {
if (auto stream = j_.info()) if (auto stream = j_.info())
logMftAct(stream, "AcceptedNew", m.masterKey, m.sequence); LOG_MANIFEST_ACTION(stream, "AcceptedNew", m.masterKey, m.sequence);
if (!revoked) if (!revoked)
signingToMasterKeys_[m.signingKey] = m.masterKey; signingToMasterKeys_[m.signingKey] = m.masterKey;
@@ -489,7 +477,7 @@ ManifestCache::applyManifest(Manifest m)
// An ephemeral key was revoked and superseded by a new key. This is // An ephemeral key was revoked and superseded by a new key. This is
// expected, but should happen infrequently. // expected, but should happen infrequently.
if (auto stream = j_.info()) if (auto stream = j_.info())
logMftAct( LOG_MANIFEST_ACTION_WITH_OLD(
stream, stream,
"AcceptedUpdate", "AcceptedUpdate",
m.masterKey, m.masterKey,
@@ -584,4 +572,9 @@ ManifestCache::save(
saveManifests(*db, dbTable, isTrusted, map_, j_); saveManifests(*db, dbTable, isTrusted, map_, j_);
} }
// Clean up macros to avoid namespace pollution
#undef LOG_MANIFEST_ACTION
#undef LOG_MANIFEST_ACTION_WITH_OLD
} // namespace ripple } // namespace ripple