Search in sources :

Example 1 with MutableThreadContextStack

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") };
}
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)

Example 2 with MutableThreadContextStack

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());
}
Also used : StringMap(org.apache.logging.log4j.util.StringMap) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Marker(org.apache.logging.log4j.Marker) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) ContextStack(org.apache.logging.log4j.ThreadContext.ContextStack) Level(org.apache.logging.log4j.Level) Test(org.junit.Test)

Aggregations

SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)2 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)2 Level (org.apache.logging.log4j.Level)1 Marker (org.apache.logging.log4j.Marker)1 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1 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 Message (org.apache.logging.log4j.message.Message)1 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)1 ThreadContextStack (org.apache.logging.log4j.spi.ThreadContextStack)1 StringMap (org.apache.logging.log4j.util.StringMap)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1