Search in sources :

Example 1 with ThreadContextStack

use of org.apache.logging.log4j.spi.ThreadContextStack in project logging-log4j2 by apache.

the class MapRewritePolicyTest method setupClass.

@BeforeClass
public static void setupClass() {
    map.put("test1", "one");
    map.put("test2", "two");
    logEvent0 = //
    Log4jLogEvent.newBuilder().setLoggerName(//
    "test").setContextMap(//
    map).setLoggerFqcn(//
    "MapRewritePolicyTest.setupClass()").setLevel(//
    Level.ERROR).setMessage(//
    new SimpleMessage("Test")).setThrown(//
    new RuntimeException("test")).setThreadName("none").setSource(new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28)).setTimeMillis(2).build();
    logEvent1 = //
    ((Log4jLogEvent) logEvent0).asBuilder().setMessage(//
    new MapMessage(map)).setSource(//
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29)).build();
    final ThreadContextStack stack = new MutableThreadContextStack(new ArrayList<>(map.values()));
    logEvent2 = //
    ((Log4jLogEvent) logEvent0).asBuilder().setContextStack(//
    stack).setMarker(//
    MarkerManager.getMarker("test")).setLevel(//
    Level.TRACE).setMessage(//
    new StructuredDataMessage("test", "Nothing", "test", map)).setTimeMillis(//
    20000000).setSource(//
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 30)).build();
    logEvent3 = //
    ((Log4jLogEvent) logEvent0).asBuilder().setContextStack(//
    stack).setLevel(//
    Level.ALL).setMessage(//
    new MapMessage(map)).setTimeMillis(//
    Long.MAX_VALUE).setSource(//
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 31)).build();
    rewrite = new KeyValuePair[] { new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three") };
}
Also used : MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) ThreadContextStack(org.apache.logging.log4j.spi.ThreadContextStack) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) KeyValuePair(org.apache.logging.log4j.core.util.KeyValuePair) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) MapMessage(org.apache.logging.log4j.message.MapMessage) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) BeforeClass(org.junit.BeforeClass)

Aggregations

Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)1 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)1 MapMessage (org.apache.logging.log4j.message.MapMessage)1 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)1 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)1 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)1 ThreadContextStack (org.apache.logging.log4j.spi.ThreadContextStack)1 BeforeClass (org.junit.BeforeClass)1