Fix issues

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
JCW
2025-09-08 17:46:23 +01:00
parent f439be39bd
commit b6d01adfda
2 changed files with 11 additions and 17 deletions

View File

@@ -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)

View File

@@ -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;