Skip to content

Commit 52becff

Browse files
committed
Fix issues
1 parent b5c4fd4 commit 52becff

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

include/xrpl/beast/utility/Journal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,13 @@ class Journal
584584
}
585585
/** @} */
586586

587+
static void
588+
resetGlobalAttributes()
589+
{
590+
std::lock_guard lock(globalLogAttributesMutex_);
591+
globalLogAttributes_ = std::nullopt;
592+
}
593+
587594
static void
588595
addGlobalAttributes(JsonLogAttributes globalLogAttributes)
589596
{

src/libxrpl/beast/utility/beast_Journal.cpp

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -203,34 +203,6 @@ Journal::formatLog(
203203
rapidjson::Value logContext;
204204
logContext.SetObject();
205205

206-
if (globalLogAttributes_)
207-
{
208-
for (auto const& [key, value] :
209-
globalLogAttributes_->contextValues().GetObject())
210-
{
211-
rapidjson::Value jsonValue;
212-
jsonValue.CopyFrom(value, currentJsonLogContext_.allocator);
213-
214-
logContext.AddMember(
215-
rapidjson::Value{key, currentJsonLogContext_.allocator},
216-
std::move(jsonValue),
217-
currentJsonLogContext_.allocator);
218-
}
219-
}
220-
221-
if (attributes.has_value())
222-
{
223-
for (auto const& [key, value] : attributes->contextValues().GetObject())
224-
{
225-
rapidjson::Value jsonValue;
226-
jsonValue.CopyFrom(value, currentJsonLogContext_.allocator);
227-
228-
logContext.AddMember(
229-
rapidjson::Value{key, currentJsonLogContext_.allocator},
230-
std::move(jsonValue),
231-
currentJsonLogContext_.allocator);
232-
}
233-
}
234206
logContext.AddMember(
235207
rapidjson::StringRef("Function"),
236208
rapidjson::StringRef(currentJsonLogContext_.location.function_name()),
@@ -274,6 +246,39 @@ Journal::formatLog(
274246
.count(),
275247
currentJsonLogContext_.allocator);
276248

249+
if (attributes.has_value())
250+
{
251+
for (auto const& [key, value] : attributes->contextValues().GetObject())
252+
{
253+
if (logContext.HasMember(key))
254+
continue;
255+
rapidjson::Value jsonValue;
256+
jsonValue.CopyFrom(value, currentJsonLogContext_.allocator);
257+
258+
logContext.AddMember(
259+
rapidjson::Value{key, currentJsonLogContext_.allocator},
260+
std::move(jsonValue),
261+
currentJsonLogContext_.allocator);
262+
}
263+
}
264+
265+
if (globalLogAttributes_)
266+
{
267+
for (auto const& [key, value] :
268+
globalLogAttributes_->contextValues().GetObject())
269+
{
270+
if (logContext.HasMember(key))
271+
continue;
272+
rapidjson::Value jsonValue;
273+
jsonValue.CopyFrom(value, currentJsonLogContext_.allocator);
274+
275+
logContext.AddMember(
276+
rapidjson::Value{key, currentJsonLogContext_.allocator},
277+
std::move(jsonValue),
278+
currentJsonLogContext_.allocator);
279+
}
280+
}
281+
277282
rapidjson::StringBuffer buffer;
278283
rapidjson::Writer writer(buffer);
279284

@@ -292,6 +297,7 @@ void
292297
Journal::disableStructuredJournal()
293298
{
294299
m_jsonLogsEnabled = false;
300+
resetGlobalAttributes();
295301
}
296302

297303
bool

0 commit comments

Comments
 (0)