@@ -118,12 +118,9 @@ private void test(
118118 ? testing ().spans ().get (0 ).getSpanContext ()
119119 : SpanContext .getInvalid ());
120120
121- List <AttributeAssertion > attributeAsserts = new ArrayList <>();
122- attributeAsserts .addAll (
123- addCodeLocationAttributes (
124- "performLogging" ,
125- equalTo (THREAD_NAME , Thread .currentThread ().getName ()),
126- equalTo (THREAD_ID , Thread .currentThread ().getId ())));
121+ List <AttributeAssertion > attributeAsserts =
122+ addCodeLocationAttributes ("performLogging" );
123+ attributeAsserts .addAll (threadAttributesAssertions ());
127124
128125 if (logException ) {
129126 attributeAsserts .addAll (
@@ -157,13 +154,10 @@ public void testContextData() {
157154 ThreadContext .clearMap ();
158155 }
159156
160- List <AttributeAssertion > assertions =
161- addCodeLocationAttributes (
162- "testContextData" ,
163- equalTo (THREAD_NAME , Thread .currentThread ().getName ()),
164- equalTo (THREAD_ID , Thread .currentThread ().getId ()),
165- equalTo (AttributeKey .stringKey ("key1" ), "val1" ),
166- equalTo (AttributeKey .stringKey ("key2" ), "val2" ));
157+ List <AttributeAssertion > assertions = addCodeLocationAttributes ("testContextData" );
158+ assertions .addAll (threadAttributesAssertions ());
159+ assertions .add (equalTo (AttributeKey .stringKey ("key1" ), "val1" ));
160+ assertions .add (equalTo (AttributeKey .stringKey ("key2" ), "val2" ));
167161
168162 testing ()
169163 .waitAndAssertLogRecords (
@@ -183,13 +177,10 @@ public void testStringMapMessage() {
183177 message .put ("key2" , "val2" );
184178 logger .info (message );
185179
186- List <AttributeAssertion > assertions =
187- addCodeLocationAttributes (
188- "testStringMapMessage" ,
189- equalTo (THREAD_NAME , Thread .currentThread ().getName ()),
190- equalTo (THREAD_ID , Thread .currentThread ().getId ()),
191- equalTo (AttributeKey .stringKey ("log4j.map_message.key1" ), "val1" ),
192- equalTo (AttributeKey .stringKey ("log4j.map_message.key2" ), "val2" ));
180+ List <AttributeAssertion > assertions = addCodeLocationAttributes ("testStringMapMessage" );
181+ assertions .addAll (threadAttributesAssertions ());
182+ assertions .add (equalTo (AttributeKey .stringKey ("log4j.map_message.key1" ), "val1" ));
183+ assertions .add (equalTo (AttributeKey .stringKey ("log4j.map_message.key2" ), "val2" ));
193184
194185 testing ()
195186 .waitAndAssertLogRecords (
@@ -210,11 +201,9 @@ public void testStringMapMessageWithSpecialAttribute() {
210201 logger .info (message );
211202
212203 List <AttributeAssertion > assertions =
213- addCodeLocationAttributes (
214- "testStringMapMessageWithSpecialAttribute" ,
215- equalTo (THREAD_NAME , Thread .currentThread ().getName ()),
216- equalTo (THREAD_ID , Thread .currentThread ().getId ()),
217- equalTo (AttributeKey .stringKey ("log4j.map_message.key1" ), "val1" ));
204+ addCodeLocationAttributes ("testStringMapMessageWithSpecialAttribute" );
205+ assertions .addAll (threadAttributesAssertions ());
206+ assertions .add (equalTo (AttributeKey .stringKey ("log4j.map_message.key1" ), "val1" ));
218207
219208 testing ()
220209 .waitAndAssertLogRecords (
@@ -235,12 +224,10 @@ public void testStructuredDataMapMessage() {
235224 logger .info (message );
236225
237226 List <AttributeAssertion > assertions =
238- addCodeLocationAttributes (
239- "testStructuredDataMapMessage" ,
240- equalTo (THREAD_NAME , Thread .currentThread ().getName ()),
241- equalTo (THREAD_ID , Thread .currentThread ().getId ()),
242- equalTo (AttributeKey .stringKey ("log4j.map_message.key1" ), "val1" ),
243- equalTo (AttributeKey .stringKey ("log4j.map_message.key2" ), "val2" ));
227+ addCodeLocationAttributes ("testStructuredDataMapMessage" );
228+ assertions .addAll (threadAttributesAssertions ());
229+ assertions .add (equalTo (AttributeKey .stringKey ("log4j.map_message.key1" ), "val1" ));
230+ assertions .add (equalTo (AttributeKey .stringKey ("log4j.map_message.key2" ), "val2" ));
244231
245232 testing ()
246233 .waitAndAssertLogRecords (
@@ -260,12 +247,9 @@ public void testMarker() {
260247
261248 logger .info (marker , "Message" );
262249
263- List <AttributeAssertion > assertions =
264- addCodeLocationAttributes (
265- "testMarker" ,
266- equalTo (THREAD_NAME , Thread .currentThread ().getName ()),
267- equalTo (THREAD_ID , Thread .currentThread ().getId ()),
268- equalTo (stringKey ("log4j.marker" ), markerName ));
250+ List <AttributeAssertion > assertions = addCodeLocationAttributes ("testMarker" );
251+ assertions .addAll (threadAttributesAssertions ());
252+ assertions .add (equalTo (stringKey ("log4j.marker" ), markerName ));
269253
270254 testing ()
271255 .waitAndAssertLogRecords (logRecord -> logRecord .hasAttributesSatisfyingExactly (assertions ));
@@ -282,16 +266,15 @@ protected static void performLogging(
282266 }
283267 }
284268
285- protected static List <AttributeAssertion > addCodeLocationAttributes (
286- String methodName , AttributeAssertion ... assertions ) {
269+ protected static List <AttributeAssertion > addCodeLocationAttributes (String methodName ) {
287270 String selector = System .getProperty ("Log4j2.contextSelector" );
288271 boolean async = selector != null && selector .endsWith ("AsyncLoggerContextSelector" );
289272 if (async && !Boolean .getBoolean ("testLatestDeps" )) {
290273 // source info is not available by default when async logger is used in non latest dep tests
291- return Arrays . asList ( assertions );
274+ return new ArrayList <>( );
292275 }
293276
294- List <AttributeAssertion > result = new ArrayList <>(Arrays . asList ( assertions ) );
277+ List <AttributeAssertion > result = new ArrayList <>();
295278 result .addAll (codeFunctionAssertions (AbstractLog4j2Test .class , methodName ));
296279 result .addAll (codeFileAndLineAssertions ("AbstractLog4j2Test.java" ));
297280 return result ;
0 commit comments