org.apache.logging.log4j.ThreadContext.ContextStack Java Examples

The following examples show how to use org.apache.logging.log4j.ThreadContext.ContextStack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMillisReturnsConstructorMillisForNormalMessage() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = null;
    final Marker marker = null;
    final String fqcn = null;
    final Level level = null;
    final Message data = null;
    final Throwable t = null;
    final ContextStack contextStack = null;
    final String threadName = null;
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(123, 456), new DummyNanoClock(1));
    assertEquals(123, evt.getTimeMillis());
    assertEquals(456, evt.getInstant().getNanoOfMillisecond());
}
 
Example #2
Source File: AsyncLogger.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public void translateTo(final RingBufferLogEvent event, final long sequence, final Object... args) {
    // Implementation note: candidate for optimization: exceeds 35 bytecodes.
    final AsyncLogger asyncLogger = (AsyncLogger) args[0];
    final StackTraceElement location = (StackTraceElement) args[1];
    final String fqcn = (String) args[2];
    final Level level = (Level) args[3];
    final Marker marker = (Marker) args[4];
    final Message message = (Message) args[5];
    final Throwable thrown = (Throwable) args[6];

    // needs shallow copy to be fast (LOG4J2-154)
    final ContextStack contextStack = ThreadContext.getImmutableStack();

    final Thread currentThread = Thread.currentThread();
    final String threadName = THREAD_NAME_CACHING_STRATEGY.getThreadName();
    event.setValues(asyncLogger, asyncLogger.getName(), marker, fqcn, level, message, thrown,
            // config properties are taken care of in the EventHandler thread
            // in the AsyncLogger#actualAsyncLog method
            CONTEXT_DATA_INJECTOR.injectContextData(null, (StringMap) event.getContextData()),
            contextStack, currentThread.getId(), threadName, currentThread.getPriority(), location,
            CLOCK, nanoClock);
}
 
Example #3
Source File: RingBufferLogEvent.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public void setValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
                      final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
                      final StringMap mutableContextData, final ContextStack aContextStack, final long threadId,
                      final String threadName, final int threadPriority, final StackTraceElement aLocation,
                      final Clock clock, final NanoClock nanoClock) {
    this.threadPriority = threadPriority;
    this.threadId = threadId;
    this.level = aLevel;
    this.threadName = threadName;
    this.loggerName = aLoggerName;
    setMessage(msg);
    initTime(clock);
    this.nanoTime = nanoClock.nanoTime();
    this.thrown = aThrowable;
    this.thrownProxy = null;
    this.marker = aMarker;
    this.fqcn = theFqcn;
    this.location = aLocation;
    this.contextData = mutableContextData;
    this.contextStack = aContextStack;
    this.asyncLogger = anAsyncLogger;
}
 
Example #4
Source File: RingBufferLogEventTranslator.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public void setBasicValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
                           final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
                           final ContextStack aContextStack, final StackTraceElement aLocation,
                           final Clock aClock, final NanoClock aNanoClock) {
    this.asyncLogger = anAsyncLogger;
    this.loggerName = aLoggerName;
    this.marker = aMarker;
    this.fqcn = theFqcn;
    this.level = aLevel;
    this.message = msg;
    this.thrown = aThrowable;
    this.contextStack = aContextStack;
    this.location = aLocation;
    this.clock = aClock;
    this.nanoClock = aNanoClock;
}
 
Example #5
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetLevelReturnsOffIfNullLevelSet() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = null;
    final Marker marker = null;
    final String fqcn = null;
    final Level level = null;
    final Message data = null;
    final Throwable t = null;
    final ContextStack contextStack = null;
    final String threadName = null;
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
    assertEquals(Level.OFF, evt.getLevel());
}
 
Example #6
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMessageReturnsNonNullMessage() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = null;
    final Marker marker = null;
    final String fqcn = null;
    final Level level = null;
    final Message data = null;
    final Throwable t = null;
    final ContextStack contextStack = null;
    final String threadName = null;
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
    assertNotNull(evt.getMessage());
}
 
Example #7
Source File: TextEncoderHelperBenchmark.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
 
Example #8
Source File: PatternLayoutComparisonBenchmark.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private static LogEvent createLog4j2Event() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
 
Example #9
Source File: PatternLayoutBenchmark.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
 
Example #10
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@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.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());
}
 
Example #11
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationDeserialization() throws IOException, ClassNotFoundException {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = "logger.name";
    final Marker marker = null;
    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 = null;
    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 ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(evt);

    final ObjectInputStream in = new FilteredObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    final RingBufferLogEvent other = (RingBufferLogEvent) in.readObject();
    assertEquals(loggerName, other.getLoggerName());
    assertEquals(marker, other.getMarker());
    assertEquals(fqcn, other.getLoggerFqcn());
    assertEquals(level, other.getLevel());
    assertEquals(data, other.getMessage());
    assertNull("null after serialization", other.getThrown());
    assertEquals(new ThrowableProxy(t), other.getThrownProxy());
    assertEquals(evt.getContextData(), other.getContextData());
    assertEquals(contextStack, other.getContextStack());
    assertEquals(threadName, other.getThreadName());
    assertEquals(location, other.getSource());
    assertEquals(12345, other.getTimeMillis());
    assertEquals(678, other.getInstant().getNanoOfMillisecond());
}
 
Example #12
Source File: DefaultThreadContextStackTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testImmutableOrNullReturnsCopyOfContents() {
    final DefaultThreadContextStack stack = createStack();
    assertTrue(!stack.isEmpty());
    final ContextStack actual = stack.getImmutableStackOrNull();
    assertNotNull(actual);
    assertEquals(stack, actual);
}
 
Example #13
Source File: DefaultThreadContextStackTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testModifyingImmutableOrNullThrowsException() {
    final DefaultThreadContextStack stack = createStack();
    final int originalSize = stack.size();
    assertTrue(originalSize > 0);
    final ContextStack actual = stack.getImmutableStackOrNull();
    assertEquals(originalSize, actual.size());

    actual.pop();
}
 
Example #14
Source File: SimpleModuleInitializer.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public void initialize(final SimpleModule simpleModule, final boolean objectMessageAsJsonObject) {
    // Workaround because mix-ins do not work for classes that already have a built-in deserializer.
    // See Jackson issue 429.
    simpleModule.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
    simpleModule.addDeserializer(ContextStack.class, new MutableThreadContextStackDeserializer());
    if (objectMessageAsJsonObject) {
        simpleModule.addSerializer(ObjectMessage.class, new ObjectMessageSerializer());
    }
    simpleModule.addSerializer(Message.class, new MessageSerializer());
}
 
Example #15
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateMementoRetainsParametersAndFormat() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    // Initialize the event with parameters
    evt.swapParameters(new Object[10]);
    final String loggerName = "logger.name";
    final Marker marker = MarkerManager.getMarker("marked man");
    final String fqcn = "f.q.c.n";
    final Level level = Level.TRACE;
    ReusableMessageFactory factory = new ReusableMessageFactory();
    Message message = factory.newMessage("Hello {}!", "World");
    try {
        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, message, t, (StringMap) evt.getContextData(),
                contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
        ((StringMap) evt.getContextData()).putValue("key", "value");

        final Message actual = evt.createMemento().getMessage();
        assertEquals("Hello {}!", actual.getFormat());
        assertArrayEquals(new String[]{"World"}, actual.getParameters());
        assertEquals("Hello World!", actual.getFormattedMessage());
    } finally {
        ReusableMessageFactory.release(message);
    }
}
 
Example #16
Source File: RingBufferLogEventTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMementoReuse() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    // Initialize the event with parameters
    evt.swapParameters(new Object[10]);
    final String loggerName = "logger.name";
    final Marker marker = MarkerManager.getMarker("marked man");
    final String fqcn = "f.q.c.n";
    final Level level = Level.TRACE;
    ReusableMessageFactory factory = new ReusableMessageFactory();
    Message message = factory.newMessage("Hello {}!", "World");
    try {
        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, message, t, (StringMap) evt.getContextData(),
                contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
        ((StringMap) evt.getContextData()).putValue("key", "value");

        final Message memento1 = evt.memento();
        final Message memento2 = evt.memento();
        assertThat(memento1, sameInstance(memento2));
    } finally {
        ReusableMessageFactory.release(message);
    }
}
 
Example #17
Source File: AbstractLogEvent.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public ContextStack getContextStack() {
    return ThreadContext.EMPTY_STACK;
}
 
Example #18
Source File: Log4jLogEventTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testBuilderCorrectlyCopiesMutableLogEvent() throws Exception {
    final StringMap contextData = new SortedArrayStringMap();
    contextData.putValue("A", "B");
    final ContextStack contextStack = ThreadContext.getImmutableStack();
    final Exception exception = new Exception("test");
    final Marker marker = MarkerManager.getMarker("EVENTTEST");
    final Message message = new SimpleMessage("foo");
    new StackTraceElement("A", "B", "file", 123);
    final String fqcn = "qualified";
    final String name = "Ceci n'est pas une pipe";
    final String threadName = "threadName";
    final MutableLogEvent event = new MutableLogEvent();
    event.setContextData(contextData);
    event.setContextStack(contextStack);
    event.setEndOfBatch(true);
    event.setIncludeLocation(true);
    //event.setSource(stackTraceElement); // cannot be explicitly set
    event.setLevel(Level.FATAL);
    event.setLoggerFqcn(fqcn);
    event.setLoggerName(name);
    event.setMarker(marker);
    event.setMessage(message);
    event.setNanoTime(1234567890L);
    event.setThreadName(threadName);
    event.setThrown(exception);
    event.setTimeMillis(987654321L);

    assertSame(contextData, event.getContextData());
    assertSame(contextStack, event.getContextStack());
    assertEquals(true, event.isEndOfBatch());
    assertEquals(true, event.isIncludeLocation());
    assertSame(Level.FATAL, event.getLevel());
    assertSame(fqcn, event.getLoggerFqcn());
    assertSame(name, event.getLoggerName());
    assertSame(marker, event.getMarker());
    assertSame(message, event.getMessage());
    assertEquals(1234567890L, event.getNanoTime());
    //assertSame(stackTraceElement, event.getSource()); // don't invoke
    assertSame(threadName, event.getThreadName());
    assertSame(exception, event.getThrown());
    assertEquals(987654321L, event.getTimeMillis());

    final LogEvent e2 = new Log4jLogEvent.Builder(event).build();
    assertEquals(contextData, e2.getContextData());
    assertSame(contextStack, e2.getContextStack());
    assertEquals(true, e2.isEndOfBatch());
    assertEquals(true, e2.isIncludeLocation());
    assertSame(Level.FATAL, e2.getLevel());
    assertSame(fqcn, e2.getLoggerFqcn());
    assertSame(name, e2.getLoggerName());
    assertSame(marker, e2.getMarker());
    assertSame(message, e2.getMessage());
    assertEquals(1234567890L, e2.getNanoTime());
    //assertSame(stackTraceElement, e2.getSource()); // don't invoke
    assertSame(threadName, e2.getThreadName());
    assertSame(exception, e2.getThrown());
    assertEquals(987654321L, e2.getTimeMillis());

    // use reflection to get value of source field in log event copy:
    // invoking the getSource() method would initialize the field
    final Field fieldSource = Log4jLogEvent.class.getDeclaredField("source");
    fieldSource.setAccessible(true);
    final Object value = fieldSource.get(e2);
    assertNull("source in copy", value);
}
 
Example #19
Source File: Log4jLogEventTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testBuilderCorrectlyCopiesAllEventAttributesInclContextData() {
    final StringMap contextData = new SortedArrayStringMap();
    contextData.putValue("A", "B");
    final ContextStack contextStack = ThreadContext.getImmutableStack();
    final Exception exception = new Exception("test");
    final Marker marker = MarkerManager.getMarker("EVENTTEST");
    final Message message = new SimpleMessage("foo");
    final StackTraceElement stackTraceElement = new StackTraceElement("A", "B", "file", 123);
    final String fqcn = "qualified";
    final String name = "Ceci n'est pas une pipe";
    final String threadName = "threadName";
    final Log4jLogEvent event = Log4jLogEvent.newBuilder() //
            .setContextData(contextData) //
            .setContextStack(contextStack) //
            .setEndOfBatch(true) //
            .setIncludeLocation(true) //
            .setLevel(Level.FATAL) //
            .setLoggerFqcn(fqcn) //
            .setLoggerName(name) //
            .setMarker(marker) //
            .setMessage(message) //
            .setNanoTime(1234567890L) //
            .setSource(stackTraceElement) //
            .setThreadName(threadName) //
            .setThrown(exception) //
            .setTimeMillis(987654321L)
            .build();

    assertSame(contextData, event.getContextData());
    assertSame(contextStack, event.getContextStack());
    assertEquals(true, event.isEndOfBatch());
    assertEquals(true, event.isIncludeLocation());
    assertSame(Level.FATAL, event.getLevel());
    assertSame(fqcn, event.getLoggerFqcn());
    assertSame(name, event.getLoggerName());
    assertSame(marker, event.getMarker());
    assertSame(message, event.getMessage());
    assertEquals(1234567890L, event.getNanoTime());
    assertSame(stackTraceElement, event.getSource());
    assertSame(threadName, event.getThreadName());
    assertSame(exception, event.getThrown());
    assertEquals(987654321L, event.getTimeMillis());

    final LogEvent event2 = new Log4jLogEvent.Builder(event).build();
    assertEquals("copy constructor builder", event2, event);
    assertEquals("same hashCode", event2.hashCode(), event.hashCode());
}
 
Example #20
Source File: Log4jLogEventTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testBuilderCorrectlyCopiesAllEventAttributes() {
    final StringMap contextData = ContextDataFactory.createContextData();
    contextData.putValue("A", "B");
    final ContextStack contextStack = ThreadContext.getImmutableStack();
    final Exception exception = new Exception("test");
    final Marker marker = MarkerManager.getMarker("EVENTTEST");
    final Message message = new SimpleMessage("foo");
    final StackTraceElement stackTraceElement = new StackTraceElement("A", "B", "file", 123);
    final String fqcn = "qualified";
    final String name = "Ceci n'est pas une pipe";
    final String threadName = "threadName";
    final Log4jLogEvent event = Log4jLogEvent.newBuilder() //
            .setContextData(contextData) //
            .setContextStack(contextStack) //
            .setEndOfBatch(true) //
            .setIncludeLocation(true) //
            .setLevel(Level.FATAL) //
            .setLoggerFqcn(fqcn) //
            .setLoggerName(name) //
            .setMarker(marker) //
            .setMessage(message) //
            .setNanoTime(1234567890L) //
            .setSource(stackTraceElement) //
            .setThreadName(threadName) //
            .setThrown(exception) //
            .setTimeMillis(987654321L)
            .build();

    assertEquals(contextData, event.getContextData());
    assertSame(contextStack, event.getContextStack());
    assertEquals(true, event.isEndOfBatch());
    assertEquals(true, event.isIncludeLocation());
    assertSame(Level.FATAL, event.getLevel());
    assertSame(fqcn, event.getLoggerFqcn());
    assertSame(name, event.getLoggerName());
    assertSame(marker, event.getMarker());
    assertSame(message, event.getMessage());
    assertEquals(1234567890L, event.getNanoTime());
    assertSame(stackTraceElement, event.getSource());
    assertSame(threadName, event.getThreadName());
    assertSame(exception, event.getThrown());
    assertEquals(987654321L, event.getTimeMillis());

    final LogEvent event2 = new Log4jLogEvent.Builder(event).build();
    assertEquals("copy constructor builder", event2, event);
    assertEquals("same hashCode", event2.hashCode(), event.hashCode());
}
 
Example #21
Source File: RingBufferLogEvent.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public ContextStack getContextStack() {
    return contextStack;
}
 
Example #22
Source File: TestLogEventMixIn.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
@Override
public abstract ContextStack getContextStack();
 
Example #23
Source File: AbstractLogEventXmlMixIn.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK)
@JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_CONTEXT_STACK_ITEM)
@Override
public abstract ContextStack getContextStack();
 
Example #24
Source File: LogEventEntityTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testToImmutable_AbstractLogEventWrapperEntity() {
    final LogEvent logEvent = new AbstractLogEventWrapperEntity() {

        private static final long serialVersionUID = 2L;

        @Override
        public ContextStack getContextStack() {
            return null;
        }

        @Override
        public Level getLevel() {
            return null;
        }

        @Override
        public String getLoggerFqcn() {
            return null;
        }

        @Override
        public String getLoggerName() {
            return null;
        }

        @Override
        public Marker getMarker() {
            return null;
        }

        @Override
        public Message getMessage() {
            return null;
        }

        @Override
        public Instant getInstant() {
            return new MutableInstant();
        }

        @Override
        public long getNanoTime() {
            return 0;
        }

        @Override
        public StackTraceElement getSource() {
            return null;
        }

        @Override
        public long getThreadId() {
            return 0;
        }

        @Override
        public String getThreadName() {
            return null;
        }

        @Override
        public int getThreadPriority() {
            return 0;
        }

        @Override
        public Throwable getThrown() {
            return null;
        }

        @Override
        public ThrowableProxy getThrownProxy() {
            return null;
        }

        @Override
        public long getTimeMillis() {
            return 0;
        }
    };
    Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
 
Example #25
Source File: LogEventJsonMixIn.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@JsonProperty(JsonConstants.ELT_CONTEXT_STACK)
@Override
public abstract ContextStack getContextStack();
 
Example #26
Source File: LogEventWithContextListMixIn.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@JsonProperty(JsonConstants.ELT_CONTEXT_STACK)
@Override
public abstract ContextStack getContextStack();
 
Example #27
Source File: DefaultThreadContextStack.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public ContextStack getImmutableStackOrNull() {
    return STACK.get();
}
 
Example #28
Source File: MutableThreadContextStack.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public ContextStack getImmutableStackOrNull() {
    return copy();
}
 
Example #29
Source File: TestLogEventMixIn.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
@Override
public abstract ContextStack getContextStack();
 
Example #30
Source File: LogEventJacksonJsonMixIn.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
@Override
public abstract ContextStack getContextStack();