Java 类org.apache.logging.log4j.spi.MutableThreadContextStack 实例源码

项目:graylog-plugin-internal-logs    文件:SerializedLogEventCodecTest.java   
private LogEvent createLogEvent(DateTime timestamp) {
    final MutableLogEvent logEvent = new MutableLogEvent();

    logEvent.setMessage(new SimpleMessage("Test"));
    logEvent.setLevel(Level.TRACE);
    logEvent.setLoggerName("org.example.Test");
    logEvent.setMarker(MarkerManager.getMarker("TestMarker"));
    logEvent.setTimeMillis(timestamp.getMillis());
    logEvent.setNanoTime(42L);

    logEvent.setContextStack(new MutableThreadContextStack(ImmutableList.of("one", "two")));
    final SortedArrayStringMap contextData = new SortedArrayStringMap(1);
    contextData.putValue("foobar", "quux");
    logEvent.setContextData(contextData);

    logEvent.setThreadId(23L);
    logEvent.setThreadName("thread-name");
    logEvent.setThreadPriority(42);

    logEvent.setThrown(new Throwable("Test", new Throwable("cause")));

    logEvent.setIncludeLocation(true);

    return logEvent.createMemento();
}
项目:log4j2    文件:ContextStackJsonAttributeConverterTest.java   
@Test
public void testConvert01() {
    ThreadContext.clearStack();
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("value1", "another2"));

    final String converted = this.converter.convertToDatabaseColumn(stack);

    assertNotNull("The converted value should not be null.", converted);

    final ThreadContext.ContextStack reversed = this.converter
            .convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", stack.asList(),
            reversed.asList());
}
项目:log4j2    文件:ContextStackJsonAttributeConverterTest.java   
@Test
public void testConvert02() {
    ThreadContext.clearStack();
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("key1", "value2", "my3"));

    final String converted = this.converter.convertToDatabaseColumn(stack);

    assertNotNull("The converted value should not be null.", converted);

    final ThreadContext.ContextStack reversed = this.converter
            .convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", stack.asList(),
            reversed.asList());
}
项目:logging-log4j2    文件:ContextStackJsonAttributeConverterTest.java   
@Test
public void testConvert01() {
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("value1", "another2"));

    final String converted = this.converter.convertToDatabaseColumn(stack);

    assertNotNull("The converted value should not be null.", converted);

    final ThreadContext.ContextStack reversed = this.converter
            .convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", stack.asList(),
            reversed.asList());
}
项目:logging-log4j2    文件:ContextStackJsonAttributeConverterTest.java   
@Test
public void testConvert02() {
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("key1", "value2", "my3"));

    final String converted = this.converter.convertToDatabaseColumn(stack);

    assertNotNull("The converted value should not be null.", converted);

    final ThreadContext.ContextStack reversed = this.converter
            .convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", stack.asList(),
            reversed.asList());
}
项目:log4j2    文件:MapRewritePolicyTest.java   
@BeforeClass
public static void setupClass() {
    map.put("test1", "one");
    map.put("test2", "two");
    logEvent0 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
    new SimpleMessage("Test"), new RuntimeException("test"), map, null, "none",
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28), 2);
    logEvent1 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
    new MapMessage(map), null, map, null, "none",
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29), 2);
final ThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>(map.values()));
    logEvent2 = new Log4jLogEvent("test", MarkerManager.getMarker("test"), "MapRewritePolicyTest.setupClass()",
    Level.TRACE, new StructuredDataMessage("test", "Nothing", "test", map), new RuntimeException("test"), null,
    stack, "none", new StackTraceElement("MapRewritePolicyTest",
    "setupClass", "MapRewritePolicyTest", 30), 20000000);
    logEvent3 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ALL, new MapMessage(map),
    null, map, stack, null, new StackTraceElement("MapRewritePolicyTest",
    "setupClass", "MapRewritePolicyTest", 31), Long.MAX_VALUE);
    rewrite = new KeyValuePair[] {new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three")};
}
项目:log4j2    文件:ContextStackAttributeConverterTest.java   
@Test
public void testConvertToDatabaseColumn01() {
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("value1", "another2"));

    assertEquals("The converted value is not correct.", "value1\nanother2",
            this.converter.convertToDatabaseColumn(stack));
}
项目:log4j2    文件:ContextStackAttributeConverterTest.java   
@Test
public void testConvertToDatabaseColumn02() {
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("key1", "value2", "my3"));

    assertEquals("The converted value is not correct.",
            "key1\nvalue2\nmy3",
            this.converter.convertToDatabaseColumn(stack));
}
项目:logging-log4j2    文件:ContextStackAttributeConverterTest.java   
@Test
public void testConvertToDatabaseColumn01() {
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("value1", "another2"));

    assertEquals("The converted value is not correct.", "value1\nanother2",
            this.converter.convertToDatabaseColumn(stack));
}
项目:logging-log4j2    文件:ContextStackAttributeConverterTest.java   
@Test
public void testConvertToDatabaseColumn02() {
    final ThreadContext.ContextStack stack = new MutableThreadContextStack(
            Arrays.asList("key1", "value2", "my3"));

    assertEquals("The converted value is not correct.",
            "key1\nvalue2\nmy3",
            this.converter.convertToDatabaseColumn(stack));
}
项目:logging-log4j2    文件:MutableThreadContextStackDeserializer.java   
@Override
public MutableThreadContextStack deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException,
        JsonProcessingException {
    final List<String> list = jp.readValueAs(new TypeReference<List<String>>() {
        // empty
    });
    return new MutableThreadContextStack(list);
}
项目:logging-log4j2    文件:MapRewritePolicyTest.java   
@BeforeClass
public static void setupClass() {
    stringMap.putValue("test1", "one");
    stringMap.putValue("test2", "two");
    map = stringMap.toMap(); 
    logEvent0 = Log4jLogEvent.newBuilder() //
            .setLoggerName("test") //
            .setContextData(stringMap) //
            .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 StringMapMessage(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 StringMapMessage(map)) //
            .setTimeMillis(Long.MAX_VALUE) //
            .setSource(new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 31)) //
            .build();
    rewrite = new KeyValuePair[]{new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three")};
}
项目:logging-log4j2    文件:RingBufferLogEventTest.java   
@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;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
    ((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.getInstant().getNanoOfMillisecond(), actual.getInstant().getNanoOfMillisecond());
    assertEquals(evt.getSource(), actual.getSource());
    assertEquals(evt.getThrownProxy(), actual.getThrownProxy());
}
项目:logging-log4j2    文件:MutableThreadContextStackDeserializer.java   
MutableThreadContextStackDeserializer() {
    super(MutableThreadContextStack.class);
}