diff --git a/Builds/levelization/results/ordering.txt b/Builds/levelization/results/ordering.txt index bf2d1db693..768a29bdc4 100644 --- a/Builds/levelization/results/ordering.txt +++ b/Builds/levelization/results/ordering.txt @@ -14,6 +14,8 @@ libxrpl.server > xrpl.basics libxrpl.server > xrpl.json libxrpl.server > xrpl.protocol libxrpl.server > xrpl.server +libxrpl.telemetry > xrpl.json +libxrpl.telemetry > xrpl.telemetry test.app > test.jtx test.app > test.rpc test.app > test.toplevel @@ -58,6 +60,7 @@ test.csf > xrpl.basics test.csf > xrpld.consensus test.csf > xrpl.json test.csf > xrpl.protocol +test.csf > xrpl.telemetry test.json > test.jtx test.json > xrpl.json test.jtx > xrpl.basics @@ -134,6 +137,8 @@ test.toplevel > test.csf test.toplevel > xrpl.json test.unit_test > xrpl.basics tests.libxrpl > xrpl.basics +tests.libxrpl > xrpl.json +tests.libxrpl > xrpl.telemetry xrpl.json > xrpl.basics xrpl.net > xrpl.basics xrpl.protocol > xrpl.basics @@ -141,9 +146,12 @@ xrpl.protocol > xrpl.json xrpl.resource > xrpl.basics xrpl.resource > xrpl.json xrpl.resource > xrpl.protocol +xrpl.resource > xrpl.telemetry xrpl.server > xrpl.basics xrpl.server > xrpl.json xrpl.server > xrpl.protocol +xrpl.server > xrpl.telemetry +xrpl.telemetry > xrpl.json xrpld.app > test.unit_test xrpld.app > xrpl.basics xrpld.app > xrpld.conditions @@ -154,6 +162,7 @@ xrpld.app > xrpl.json xrpld.app > xrpl.net xrpld.app > xrpl.protocol xrpld.app > xrpl.resource +xrpld.app > xrpl.telemetry xrpld.conditions > xrpl.basics xrpld.conditions > xrpl.protocol xrpld.consensus > xrpl.basics @@ -163,6 +172,7 @@ xrpld.core > xrpl.basics xrpld.core > xrpl.json xrpld.core > xrpl.net xrpld.core > xrpl.protocol +xrpld.core > xrpl.telemetry xrpld.ledger > xrpl.basics xrpld.ledger > xrpl.json xrpld.ledger > xrpl.protocol diff --git a/include/xrpl/logging/JsonLogs.h b/include/xrpl/logging/JsonLogs.h deleted file mode 100644 index 1eb2ba8c8a..0000000000 --- a/include/xrpl/logging/JsonLogs.h +++ /dev/null @@ -1,223 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_LOGGING_STRUCTUREDJOURNAL_H_INCLUDED -#define RIPPLE_LOGGING_STRUCTUREDJOURNAL_H_INCLUDED - -#include -#include -#include -#include - -#include -#include -#include - -namespace ripple { -namespace log { - -template -class LogParameter -{ -public: - template - LogParameter(char const* name, TArg&& value) - : name_(name), value_(std::forward(value)) - { - } - -private: - char const* name_; - T value_; - - template - friend std::ostream& - operator<<(std::ostream& os, LogParameter const&); -}; - -template -class LogField -{ -public: - template - LogField(char const* name, TArg&& value) - : name_(name), value_(std::forward(value)) - { - } - -private: - char const* name_; - T value_; - - template - friend std::ostream& - operator<<(std::ostream& os, LogField const&); -}; - -class JsonLogAttributes : public beast::Journal::StructuredLogAttributes -{ -public: - using AttributeFields = std::unordered_map; - using Pair = AttributeFields::value_type; - - explicit JsonLogAttributes(AttributeFields contextValues = {}); - - void - setModuleName(std::string const& name) override; - - std::unique_ptr - clone() const override; - - void - combine(std::unique_ptr const& context) override; - - void - combine(std::unique_ptr&& context) override; - - AttributeFields& - contextValues() - { - return contextValues_; - } - -private: - AttributeFields contextValues_; -}; - -class JsonStructuredJournal : public beast::Journal::StructuredJournalImpl -{ -private: - struct Logger - { - std::source_location location = {}; - Json::Value messageParams; - - Logger() = default; - Logger( - JsonStructuredJournal const* journal, - std::source_location location); - - void - write( - beast::Journal::Sink* sink, - beast::severities::Severity level, - std::string const& text, - beast::Journal::StructuredLogAttributes* context) const; - }; - - [[nodiscard]] Logger - logger(std::source_location location) const; - - static thread_local Logger currentLogger_; - - template - friend std::ostream& - operator<<(std::ostream& os, LogParameter const&); - - template - friend std::ostream& - operator<<(std::ostream& os, LogField const&); - -public: - void - initMessageContext(std::source_location location) override; - - void - flush( - beast::Journal::Sink* sink, - beast::severities::Severity level, - std::string const& text, - beast::Journal::StructuredLogAttributes* context) override; -}; - -template -std::ostream& -operator<<(std::ostream& os, LogParameter const& param) -{ - using ValueType = std::decay_t; - // TODO: Update the Json library to support 64-bit integer values. - if constexpr ( - std::constructible_from && - (!std::is_integral_v || - sizeof(ValueType) <= sizeof(Json::Int))) - { - JsonStructuredJournal::currentLogger_.messageParams[param.name_] = - Json::Value{param.value_}; - return os << param.value_; - } - else - { - std::ostringstream oss; - oss << param.value_; - - JsonStructuredJournal::currentLogger_.messageParams[param.name_] = - oss.str(); - return os << oss.str(); - } -} - -template -std::ostream& -operator<<(std::ostream& os, LogField const& param) -{ - using ValueType = std::decay_t; - // TODO: Update the Json library to support 64-bit integer values. - if constexpr ( - std::constructible_from && - (!std::is_integral_v || - sizeof(ValueType) <= sizeof(Json::Int))) - { - JsonStructuredJournal::currentLogger_.messageParams[param.name_] = - Json::Value{param.value_}; - } - else - { - std::ostringstream oss; - oss << param.value_; - - JsonStructuredJournal::currentLogger_.messageParams[param.name_] = - oss.str(); - } - return os; -} - -template -LogParameter -param(char const* name, T&& value) -{ - return LogParameter{name, std::forward(value)}; -} - -template -LogField -field(char const* name, T&& value) -{ - return LogField{name, std::forward(value)}; -} - -[[nodiscard]] inline std::unique_ptr -attributes(std::initializer_list const& fields) -{ - return std::make_unique(fields); -} - -} // namespace log -} // namespace ripple - -#endif diff --git a/include/xrpl/telemetry/JsonLogs.h b/include/xrpl/telemetry/JsonLogs.h index df8fe47625..8ff996f41f 100644 --- a/include/xrpl/telemetry/JsonLogs.h +++ b/include/xrpl/telemetry/JsonLogs.h @@ -23,12 +23,10 @@ #include #include -#include #include #include -namespace ripple { -namespace log { +namespace ripple::log { template class LogParameter @@ -215,7 +213,6 @@ attributes(std::initializer_list const& fields) return std::make_unique(fields); } -} // namespace log -} // namespace ripple +} // namespace ripple::log #endif diff --git a/src/libxrpl/logging/JsonLogs.cpp b/src/libxrpl/logging/JsonLogs.cpp deleted file mode 100644 index b447f1796b..0000000000 --- a/src/libxrpl/logging/JsonLogs.cpp +++ /dev/null @@ -1,138 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include - -namespace ripple { -namespace log { - -thread_local JsonStructuredJournal::Logger - JsonStructuredJournal::currentLogger_{}; - -JsonLogAttributes::JsonLogAttributes(AttributeFields contextValues) - : contextValues_(std::move(contextValues)) -{ -} - -void -JsonLogAttributes::setModuleName(std::string const& name) -{ - contextValues()["Module"] = name; -} - -std::unique_ptr -JsonLogAttributes::clone() const -{ - return std::make_unique(*this); -} - -void -JsonLogAttributes::combine( - std::unique_ptr const& context) -{ - auto structuredContext = - static_cast(context.get()); - contextValues_.insert( - structuredContext->contextValues_.begin(), - structuredContext->contextValues_.end()); -} - -void -JsonLogAttributes::combine(std::unique_ptr&& context) -{ - auto structuredContext = - static_cast(context.get()); - - if (contextValues_.empty()) - { - contextValues_ = std::move(structuredContext->contextValues_); - } - else - { - contextValues_.insert( - structuredContext->contextValues_.begin(), - structuredContext->contextValues_.end()); - } -} - -JsonStructuredJournal::Logger::Logger( - JsonStructuredJournal const* journal, - std::source_location location) - : location(location) -{ -} - -void -JsonStructuredJournal::Logger::write( - beast::Journal::Sink* sink, - beast::severities::Severity level, - std::string const& text, - beast::Journal::StructuredLogAttributes* context) const -{ - Json::Value globalContext; - if (context) - { - auto jsonContext = static_cast(context); - for (auto const& [key, value] : jsonContext->contextValues()) - { - globalContext[key] = value; - } - } - globalContext["Function"] = location.function_name(); - globalContext["File"] = location.file_name(); - globalContext["Line"] = location.line(); - std::stringstream threadIdStream; - threadIdStream << std::this_thread::get_id(); - globalContext["ThreadId"] = threadIdStream.str(); - globalContext["Params"] = messageParams; - globalContext["Level"] = beast::severities::to_string(level); - globalContext["Message"] = text; - globalContext["Time"] = - to_string(std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count()); - - sink->write(level, to_string(globalContext)); -} - -JsonStructuredJournal::Logger -JsonStructuredJournal::logger(std::source_location location) const -{ - return Logger{this, location}; -} - -void -JsonStructuredJournal::initMessageContext(std::source_location location) -{ - currentLogger_ = logger(location); -} - -void -JsonStructuredJournal::flush( - beast::Journal::Sink* sink, - beast::severities::Severity level, - std::string const& text, - beast::Journal::StructuredLogAttributes* context) -{ - currentLogger_.write(sink, level, text, context); -} - -} // namespace log -} // namespace ripple