From 67c1e7ce56a3b5dc0c2765ccb276ce3c8dadb387 Mon Sep 17 00:00:00 2001 From: JCW Date: Tue, 2 Sep 2025 18:17:19 +0100 Subject: [PATCH] Fix issues Signed-off-by: JCW --- include/xrpl/beast/utility/Journal.h | 76 ++++++++++++++++++++-------- src/xrpld/app/main/Application.cpp | 4 +- src/xrpld/app/main/Application.h | 2 +- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index 5723006f09..0e26164ece 100644 --- a/include/xrpl/beast/utility/Journal.h +++ b/include/xrpl/beast/utility/Journal.h @@ -79,6 +79,16 @@ operator<<(std::ostream& os, LogParameter const& param); namespace beast { +// Forward declaration for use in interfaces +namespace detail { +class SimpleJsonWriter; +} + +// Type alias for journal attribute factory functions +using JournalAttributesFactory = void(detail::SimpleJsonWriter&); + +namespace detail { + class SimpleJsonWriter { public: @@ -125,6 +135,16 @@ public: stream_.append("\","sv); } std::string_view + writeInt(std::int8_t val) const + { + return pushNumber(val, stream_); + } + std::string_view + writeInt(std::int16_t val) const + { + return pushNumber(val, stream_); + } + std::string_view writeInt(std::int32_t val) const { return pushNumber(val, stream_); @@ -135,6 +155,21 @@ public: return pushNumber(val, stream_); } std::string_view + writeUInt(std::size_t val) const + { + return pushNumber(val, stream_); + } + std::string_view + writeUInt(std::uint8_t val) const + { + return pushNumber(val, stream_); + } + std::string_view + writeUInt(std::uint16_t val) const + { + return pushNumber(val, stream_); + } + std::string_view writeUInt(std::uint32_t val) const { return pushNumber(val, stream_); @@ -259,6 +294,8 @@ private: std::string& stream_; }; +} // namespace detail + /** A namespace for easy access to logging severity values. */ namespace severities { /** Severity level / threshold of a Journal message. */ @@ -312,7 +349,7 @@ public: class JsonLogContext { std::string buffer_; - SimpleJsonWriter messageParamsWriter_; + detail::SimpleJsonWriter messageParamsWriter_; public: JsonLogContext() : messageParamsWriter_(buffer_) @@ -320,7 +357,7 @@ public: buffer_.reserve(1024 * 5); } - SimpleJsonWriter& + detail::SimpleJsonWriter& writer() { return messageParamsWriter_; @@ -596,7 +633,7 @@ public: : m_name(other.m_name), m_sink(other.m_sink) { std::string stream{other.m_attributesJson}; - SimpleJsonWriter writer{stream}; + detail::SimpleJsonWriter writer{stream}; if (other.m_attributesJson.empty()) { writer.startObject(); @@ -620,7 +657,7 @@ public: : m_name(name), m_sink(&sink) { std::string stream; - SimpleJsonWriter writer{stream}; + detail::SimpleJsonWriter writer{stream}; writer.startObject(); attributesFactory(writer); m_attributesJson = std::move(stream); @@ -741,7 +778,7 @@ public: auto isEmpty = globalLogAttributesJson_.empty(); std::string stream{std::move(globalLogAttributesJson_)}; - SimpleJsonWriter writer{stream}; + detail::SimpleJsonWriter writer{stream}; if (isEmpty) { writer.startObject(); @@ -860,7 +897,7 @@ namespace ripple::log { namespace detail { template -concept CanToChars = requires(T val) { +concept ToCharsFormattable = requires(T val) { { to_chars(std::declval(), std::declval(), val) } -> std::convertible_to; @@ -869,14 +906,22 @@ concept CanToChars = requires(T val) { template void setJsonValue( - beast::SimpleJsonWriter& writer, + beast::detail::SimpleJsonWriter& writer, char const* name, T&& value, std::ostream* outStream) { using ValueType = std::decay_t; writer.writeKey(name); - if constexpr (std::is_integral_v) + if constexpr (std::is_same_v) + { + auto sv = writer.writeBool(value); + if (outStream) + { + outStream->write(sv.data(), sv.size()); + } + } + else if constexpr (std::is_integral_v) { std::string_view sv; if constexpr (std::is_signed_v) @@ -901,14 +946,6 @@ setJsonValue( outStream->write(sv.data(), sv.size()); } } - else if constexpr (std::is_same_v) - { - auto sv = writer.writeBool(value); - if (outStream) - { - outStream->write(sv.data(), sv.size()); - } - } else if constexpr ( std::is_same_v || std::is_same_v) @@ -929,15 +966,14 @@ setJsonValue( } else { - if constexpr (CanToChars) + if constexpr (ToCharsFormattable) { char buffer[1024]; std::to_chars_result result = to_chars(std::begin(buffer), std::end(buffer), value); if (result.ec == std::errc{}) { - std::string_view sv; - sv = {std::begin(buffer), result.ptr}; + std::string_view sv{std::begin(buffer), result.ptr}; writer.writeString(sv); if (outStream) { @@ -1010,7 +1046,7 @@ template [[nodiscard]] auto attributes(Pair&&... pairs) { - return [&](beast::SimpleJsonWriter& writer) { + return [&](beast::detail::SimpleJsonWriter& writer) { (detail::setJsonValue(writer, pairs.first, pairs.second, nullptr), ...); }; } diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 2e4b60f55e..e9c480a6a6 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -835,7 +835,7 @@ public: beast::Journal journal( std::string const& name, - std::function const& attributes) + std::function const& attributes) override; beast::Journal @@ -2176,7 +2176,7 @@ ApplicationImp::serverOkay(std::string& reason) beast::Journal ApplicationImp::journal( std::string const& name, - std::function const& attributes) + std::function const& attributes) { return logs_->journal(name, std::move(attributes)); } diff --git a/src/xrpld/app/main/Application.h b/src/xrpld/app/main/Application.h index 0dc9713594..de3225aa98 100644 --- a/src/xrpld/app/main/Application.h +++ b/src/xrpld/app/main/Application.h @@ -260,7 +260,7 @@ public: virtual beast::Journal journal( std::string const& name, - std::function const& attributes) = 0; + std::function const& attributes) = 0; virtual beast::Journal journal(std::string const& name) = 0;