@@ -203,34 +203,6 @@ Journal::formatLog(
203
203
rapidjson::Value logContext;
204
204
logContext.SetObject ();
205
205
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
- }
234
206
logContext.AddMember (
235
207
rapidjson::StringRef (" Function" ),
236
208
rapidjson::StringRef (currentJsonLogContext_.location .function_name ()),
@@ -274,6 +246,39 @@ Journal::formatLog(
274
246
.count (),
275
247
currentJsonLogContext_.allocator );
276
248
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
+
277
282
rapidjson::StringBuffer buffer;
278
283
rapidjson::Writer writer (buffer);
279
284
292
297
Journal::disableStructuredJournal ()
293
298
{
294
299
m_jsonLogsEnabled = false ;
300
+ resetGlobalAttributes ();
295
301
}
296
302
297
303
bool
0 commit comments