use of org.apache.logging.log4j.spi.MutableThreadContextStack 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") };
}
use of org.apache.logging.log4j.spi.MutableThreadContextStack in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testCreateMementoReturnsCopy.
@SuppressWarnings("deprecation")
@Test
public void testCreateMementoReturnsCopy() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
final String loggerName = "logger.name";
final Marker marker = MarkerManager.getMarker("marked man");
final String fqcn = "f.q.c.n";
final Level level = Level.TRACE;
final Message data = new SimpleMessage("message");
final Throwable t = new InternalError("not a real error");
final ContextStack contextStack = new MutableThreadContextStack(Arrays.asList("a", "b"));
final String threadName = "main";
final StackTraceElement location = null;
final long currentTimeMillis = 12345;
final long nanoTime = 1;
evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, currentTimeMillis, nanoTime);
((StringMap) evt.getContextData()).putValue("key", "value");
final LogEvent actual = evt.createMemento();
assertEquals(evt.getLoggerName(), actual.getLoggerName());
assertEquals(evt.getMarker(), actual.getMarker());
assertEquals(evt.getLoggerFqcn(), actual.getLoggerFqcn());
assertEquals(evt.getLevel(), actual.getLevel());
assertEquals(evt.getMessage(), actual.getMessage());
assertEquals(evt.getThrown(), actual.getThrown());
assertEquals(evt.getContextMap(), actual.getContextMap());
assertEquals(evt.getContextData(), actual.getContextData());
assertEquals(evt.getContextStack(), actual.getContextStack());
assertEquals(evt.getThreadName(), actual.getThreadName());
assertEquals(evt.getTimeMillis(), actual.getTimeMillis());
assertEquals(evt.getSource(), actual.getSource());
assertEquals(evt.getThrownProxy(), actual.getThrownProxy());
}
Aggregations