diff --git a/src/libxrpl/basics/Log.cpp b/src/libxrpl/basics/Log.cpp index cdb4b5820b..b8463b1510 100644 --- a/src/libxrpl/basics/Log.cpp +++ b/src/libxrpl/basics/Log.cpp @@ -387,9 +387,9 @@ Logs::format( beast::severities::Severity severity, std::string const& partition) { - output = message; - output.reserve(output.size() + partition.size() + 100); - output += to_string(std::chrono::system_clock::now()); + output.reserve(message.size() + partition.size() + 100); + + output = to_string(std::chrono::system_clock::now()); output += " "; if (!partition.empty()) @@ -421,6 +421,7 @@ Logs::format( break; } + output += message; // Limit the maximum length of the output if (output.size() > maximumMessageCharacters) diff --git a/src/tests/libxrpl/basics/log.cpp b/src/tests/libxrpl/basics/log.cpp index 4ad24a896d..f0886d4c6e 100644 --- a/src/tests/libxrpl/basics/log.cpp +++ b/src/tests/libxrpl/basics/log.cpp @@ -90,8 +90,13 @@ public: bool console) { std::string s; - format(s, text, level, partition); - logStream_.append(s); + std::string_view result = text; + if (!beast::Journal::isStructuredJournalEnabled()) + { + format(s, text, level, partition); + result = s; + } + logStream_.append(result); } }; @@ -120,18 +125,6 @@ TEST_CASE("Test format output") CHECK(output != "Message"); } -TEST_CASE("Test format output when structured logs are enabled") -{ - beast::Journal::enableStructuredJournal(); - - std::string output; - Logs::format(output, "Message", beast::severities::kDebug, "Test"); - - CHECK(output == "Message"); - - beast::Journal::disableStructuredJournal(); -} - TEST_CASE("Enable json logs") { std::string logStream;