Log size optimise

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
JCW
2025-09-10 01:14:16 +01:00
parent 05b89b7082
commit d8b840ca5c
4 changed files with 46 additions and 27 deletions

View File

@@ -324,6 +324,7 @@ public:
{
std::string buffer_;
detail::SimpleJsonWriter messageParamsWriter_;
bool hasMessageParams_ = false;
public:
JsonLogContext() : messageParamsWriter_(buffer_)
@@ -331,6 +332,26 @@ public:
buffer_.reserve(1024 * 5);
}
void
startMessageParams()
{
if (!hasMessageParams_)
{
writer().writeKey("Data");
writer().startObject();
hasMessageParams_ = true;
}
}
void
endMessageParams()
{
if (hasMessageParams_)
{
writer().endObject();
}
}
detail::SimpleJsonWriter&
writer()
{
@@ -1014,6 +1035,7 @@ operator<<(std::ostream& os, LogParameter<T> const& param)
os << param.value_;
return os;
}
beast::Journal::currentJsonLogContext_.startMessageParams();
detail::setJsonValue(
beast::Journal::currentJsonLogContext_.writer(),
param.name_,
@@ -1028,6 +1050,7 @@ operator<<(std::ostream& os, LogField<T> const& param)
{
if (!beast::Journal::m_jsonLogsEnabled)
return os;
beast::Journal::currentJsonLogContext_.startMessageParams();
detail::setJsonValue(
beast::Journal::currentJsonLogContext_.writer(),
param.name_,