mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Log size optimise
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
@@ -324,6 +324,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::string buffer_;
|
std::string buffer_;
|
||||||
detail::SimpleJsonWriter messageParamsWriter_;
|
detail::SimpleJsonWriter messageParamsWriter_;
|
||||||
|
bool hasMessageParams_ = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JsonLogContext() : messageParamsWriter_(buffer_)
|
JsonLogContext() : messageParamsWriter_(buffer_)
|
||||||
@@ -331,6 +332,26 @@ public:
|
|||||||
buffer_.reserve(1024 * 5);
|
buffer_.reserve(1024 * 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
startMessageParams()
|
||||||
|
{
|
||||||
|
if (!hasMessageParams_)
|
||||||
|
{
|
||||||
|
writer().writeKey("Data");
|
||||||
|
writer().startObject();
|
||||||
|
hasMessageParams_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endMessageParams()
|
||||||
|
{
|
||||||
|
if (hasMessageParams_)
|
||||||
|
{
|
||||||
|
writer().endObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
detail::SimpleJsonWriter&
|
detail::SimpleJsonWriter&
|
||||||
writer()
|
writer()
|
||||||
{
|
{
|
||||||
@@ -1014,6 +1035,7 @@ operator<<(std::ostream& os, LogParameter<T> const& param)
|
|||||||
os << param.value_;
|
os << param.value_;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
beast::Journal::currentJsonLogContext_.startMessageParams();
|
||||||
detail::setJsonValue(
|
detail::setJsonValue(
|
||||||
beast::Journal::currentJsonLogContext_.writer(),
|
beast::Journal::currentJsonLogContext_.writer(),
|
||||||
param.name_,
|
param.name_,
|
||||||
@@ -1028,6 +1050,7 @@ operator<<(std::ostream& os, LogField<T> const& param)
|
|||||||
{
|
{
|
||||||
if (!beast::Journal::m_jsonLogsEnabled)
|
if (!beast::Journal::m_jsonLogsEnabled)
|
||||||
return os;
|
return os;
|
||||||
|
beast::Journal::currentJsonLogContext_.startMessageParams();
|
||||||
detail::setJsonValue(
|
detail::setJsonValue(
|
||||||
beast::Journal::currentJsonLogContext_.writer(),
|
beast::Journal::currentJsonLogContext_.writer(),
|
||||||
param.name_,
|
param.name_,
|
||||||
|
|||||||
@@ -201,14 +201,14 @@ Logs::write(
|
|||||||
result = s;
|
result = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Console output still immediate for responsiveness
|
|
||||||
if (!silent_)
|
|
||||||
std::cerr << result << '\n';
|
|
||||||
|
|
||||||
// Add to batch buffer for file output
|
// Add to batch buffer for file output
|
||||||
{
|
{
|
||||||
std::lock_guard lock(batchMutex_);
|
std::lock_guard lock(batchMutex_);
|
||||||
|
|
||||||
|
// Console output still immediate for responsiveness
|
||||||
|
if (!silent_)
|
||||||
|
std::cerr << result << '\n';
|
||||||
|
|
||||||
size_t logSize = result.size() + 1; // +1 for newline
|
size_t logSize = result.size() + 1; // +1 for newline
|
||||||
|
|
||||||
// If log won't fit in current write buffer, flush first
|
// If log won't fit in current write buffer, flush first
|
||||||
|
|||||||
@@ -216,7 +216,6 @@ Journal::JsonLogContext::reset(
|
|||||||
ThreadIdStringInitializer()
|
ThreadIdStringInitializer()
|
||||||
{
|
{
|
||||||
std::stringstream threadIdStream;
|
std::stringstream threadIdStream;
|
||||||
threadIdStream.imbue(std::locale::classic());
|
|
||||||
threadIdStream << std::this_thread::get_id();
|
threadIdStream << std::this_thread::get_id();
|
||||||
value = threadIdStream.str();
|
value = threadIdStream.str();
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,7 @@ Journal::JsonLogContext::reset(
|
|||||||
|
|
||||||
if (!journalAttributesJson.empty())
|
if (!journalAttributesJson.empty())
|
||||||
{
|
{
|
||||||
writer().writeKey("JournalParams");
|
writer().writeKey("Jnl");
|
||||||
writer().writeRaw(journalAttributesJson);
|
writer().writeRaw(journalAttributesJson);
|
||||||
writer().endObject();
|
writer().endObject();
|
||||||
}
|
}
|
||||||
@@ -238,50 +237,45 @@ Journal::JsonLogContext::reset(
|
|||||||
std::shared_lock lock(globalLogAttributesMutex_);
|
std::shared_lock lock(globalLogAttributesMutex_);
|
||||||
if (!globalLogAttributesJson_.empty())
|
if (!globalLogAttributesJson_.empty())
|
||||||
{
|
{
|
||||||
writer().writeKey("GlobalParams");
|
writer().writeKey("Gbl");
|
||||||
writer().writeRaw(globalLogAttributesJson_);
|
writer().writeRaw(globalLogAttributesJson_);
|
||||||
writer().endObject();
|
writer().endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writer().writeKey("ModuleName");
|
writer().writeKey("Mtd");
|
||||||
writer().writeString(moduleName);
|
|
||||||
writer().writeKey("Metadata");
|
|
||||||
writer().startObject();
|
writer().startObject();
|
||||||
|
|
||||||
writer().writeKey("Function");
|
writer().writeKey("Mdl");
|
||||||
writer().writeString(location.function_name());
|
writer().writeString(moduleName);
|
||||||
|
|
||||||
writer().writeKey("File");
|
writer().writeKey("Fl");
|
||||||
|
constexpr size_t FILE_NAME_KEEP_CHARS = 20;
|
||||||
std::string_view fileName = location.file_name();
|
std::string_view fileName = location.file_name();
|
||||||
constexpr size_t KEEP_CHARS = 10;
|
std::string_view trimmedFileName = (fileName.size() > FILE_NAME_KEEP_CHARS)
|
||||||
std::string_view trimmedFileName = (fileName.size() > KEEP_CHARS)
|
? fileName.substr(fileName.size() - FILE_NAME_KEEP_CHARS)
|
||||||
? fileName.substr(fileName.size() - KEEP_CHARS)
|
|
||||||
: fileName;
|
: fileName;
|
||||||
writer().writeString(trimmedFileName);
|
writer().writeString(trimmedFileName);
|
||||||
|
|
||||||
writer().writeKey("Line");
|
writer().writeKey("Ln");
|
||||||
writer().writeUInt(location.line());
|
writer().writeUInt(location.line());
|
||||||
|
|
||||||
writer().writeKey("ThreadId");
|
writer().writeKey("ThId");
|
||||||
writer().writeString(threadId.value);
|
writer().writeString(threadId.value);
|
||||||
|
|
||||||
auto severityStr = to_string(severity);
|
auto severityStr = to_string(severity);
|
||||||
writer().writeKey("Level");
|
writer().writeKey("Lv");
|
||||||
writer().writeString(severityStr);
|
writer().writeString(severityStr);
|
||||||
|
|
||||||
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch())
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
.count();
|
.count();
|
||||||
writer().writeKey("Timestamp");
|
writer().writeKey("Tm");
|
||||||
writer().writeInt(nowMs);
|
|
||||||
writer().writeKey("Time");
|
|
||||||
writer().writeString(fastTimestampToString(nowMs));
|
writer().writeString(fastTimestampToString(nowMs));
|
||||||
|
|
||||||
writer().endObject();
|
writer().endObject();
|
||||||
|
|
||||||
writer().writeKey("MessageParams");
|
hasMessageParams_ = false;
|
||||||
writer().startObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -302,9 +296,9 @@ Journal::formatLog(std::string const& message)
|
|||||||
|
|
||||||
auto& writer = currentJsonLogContext_.writer();
|
auto& writer = currentJsonLogContext_.writer();
|
||||||
|
|
||||||
writer.endObject();
|
currentJsonLogContext_.endMessageParams();
|
||||||
|
|
||||||
writer.writeKey("Message");
|
writer.writeKey("Msg");
|
||||||
writer.writeString(message);
|
writer.writeString(message);
|
||||||
|
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
|
|||||||
@@ -1139,8 +1139,10 @@ RclConsensusLogger::~RclConsensusLogger()
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
beast::detail::SimpleJsonWriter writer{buffer};
|
beast::detail::SimpleJsonWriter writer{buffer};
|
||||||
writer.startObject();
|
writer.startObject();
|
||||||
writer.writeKey("Message");
|
writer.writeKey("Msg");
|
||||||
writer.writeString(outSs.str());
|
writer.writeString(outSs.str());
|
||||||
|
writer.writeKey("Tm");
|
||||||
|
writer.writeString(to_string(std::chrono::system_clock::now()));
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
j_.sink().writeAlways(beast::severities::kInfo, writer.finish());
|
j_.sink().writeAlways(beast::severities::kInfo, writer.finish());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user