From 52becffa489b9a1bf394a5985d1082609845da71 Mon Sep 17 00:00:00 2001 From: JCW Date: Thu, 28 Aug 2025 23:04:56 +0100 Subject: [PATCH] Fix issues --- include/xrpl/beast/utility/Journal.h | 7 +++ src/libxrpl/beast/utility/beast_Journal.cpp | 62 +++++++++++---------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index d8f2e369ba..d2d9ae0d57 100644 --- a/include/xrpl/beast/utility/Journal.h +++ b/include/xrpl/beast/utility/Journal.h @@ -584,6 +584,13 @@ public: } /** @} */ + static void + resetGlobalAttributes() + { + std::lock_guard lock(globalLogAttributesMutex_); + globalLogAttributes_ = std::nullopt; + } + static void addGlobalAttributes(JsonLogAttributes globalLogAttributes) { diff --git a/src/libxrpl/beast/utility/beast_Journal.cpp b/src/libxrpl/beast/utility/beast_Journal.cpp index 122bc11f5e..a710e7754c 100644 --- a/src/libxrpl/beast/utility/beast_Journal.cpp +++ b/src/libxrpl/beast/utility/beast_Journal.cpp @@ -203,34 +203,6 @@ Journal::formatLog( rapidjson::Value logContext; logContext.SetObject(); - if (globalLogAttributes_) - { - for (auto const& [key, value] : - globalLogAttributes_->contextValues().GetObject()) - { - rapidjson::Value jsonValue; - jsonValue.CopyFrom(value, currentJsonLogContext_.allocator); - - logContext.AddMember( - rapidjson::Value{key, currentJsonLogContext_.allocator}, - std::move(jsonValue), - currentJsonLogContext_.allocator); - } - } - - if (attributes.has_value()) - { - for (auto const& [key, value] : attributes->contextValues().GetObject()) - { - rapidjson::Value jsonValue; - jsonValue.CopyFrom(value, currentJsonLogContext_.allocator); - - logContext.AddMember( - rapidjson::Value{key, currentJsonLogContext_.allocator}, - std::move(jsonValue), - currentJsonLogContext_.allocator); - } - } logContext.AddMember( rapidjson::StringRef("Function"), rapidjson::StringRef(currentJsonLogContext_.location.function_name()), @@ -274,6 +246,39 @@ Journal::formatLog( .count(), currentJsonLogContext_.allocator); + if (attributes.has_value()) + { + for (auto const& [key, value] : attributes->contextValues().GetObject()) + { + if (logContext.HasMember(key)) + continue; + rapidjson::Value jsonValue; + jsonValue.CopyFrom(value, currentJsonLogContext_.allocator); + + logContext.AddMember( + rapidjson::Value{key, currentJsonLogContext_.allocator}, + std::move(jsonValue), + currentJsonLogContext_.allocator); + } + } + + if (globalLogAttributes_) + { + for (auto const& [key, value] : + globalLogAttributes_->contextValues().GetObject()) + { + if (logContext.HasMember(key)) + continue; + rapidjson::Value jsonValue; + jsonValue.CopyFrom(value, currentJsonLogContext_.allocator); + + logContext.AddMember( + rapidjson::Value{key, currentJsonLogContext_.allocator}, + std::move(jsonValue), + currentJsonLogContext_.allocator); + } + } + rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); @@ -292,6 +297,7 @@ void Journal::disableStructuredJournal() { m_jsonLogsEnabled = false; + resetGlobalAttributes(); } bool