Search in sources :

Example 6 with ContextStack

use of org.apache.logging.log4j.ThreadContext.ContextStack in project logging-log4j2 by apache.

the class TextEncoderHelperBenchmark method createLogEvent.

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

Example 7 with ContextStack

use of org.apache.logging.log4j.ThreadContext.ContextStack in project logging-log4j2 by apache.

the class PatternLayoutBenchmark method createLogEvent.

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

Example 8 with ContextStack

use of org.apache.logging.log4j.ThreadContext.ContextStack in project logging-log4j2 by apache.

the class RingBufferLogEventTest method testCreateMementoRetainsParametersAndFormat.

@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;
    final ReusableMessageFactory factory = new ReusableMessageFactory();
    final 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);
    }
}
Also used : StringMap(org.apache.logging.log4j.util.StringMap) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) 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) ReusableMessageFactory(org.apache.logging.log4j.message.ReusableMessageFactory) FixedPreciseClock(org.apache.logging.log4j.core.time.internal.FixedPreciseClock) DummyNanoClock(org.apache.logging.log4j.core.time.internal.DummyNanoClock) Level(org.apache.logging.log4j.Level) Test(org.junit.Test)

Example 9 with ContextStack

use of org.apache.logging.log4j.ThreadContext.ContextStack in project logging-log4j2 by apache.

the class RingBufferLogEventTest method testIsPopulated.

/**
 * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2816">LOG4J2-2816</a>
 */
@Test
public void testIsPopulated() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    assertFalse(evt.isPopulated());
    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));
    assertTrue(evt.isPopulated());
    evt.clear();
    assertFalse(evt.isPopulated());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) FixedPreciseClock(org.apache.logging.log4j.core.time.internal.FixedPreciseClock) DummyNanoClock(org.apache.logging.log4j.core.time.internal.DummyNanoClock) Level(org.apache.logging.log4j.Level) Marker(org.apache.logging.log4j.Marker) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) ContextStack(org.apache.logging.log4j.ThreadContext.ContextStack) Test(org.junit.Test)

Example 10 with ContextStack

use of org.apache.logging.log4j.ThreadContext.ContextStack in project logging-log4j2 by apache.

the class RingBufferLogEventTest method testGetLevelReturnsOffIfNullLevelSet.

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

Aggregations

ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)19 Marker (org.apache.logging.log4j.Marker)17 Message (org.apache.logging.log4j.message.Message)17 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)16 Level (org.apache.logging.log4j.Level)13 StringMap (org.apache.logging.log4j.util.StringMap)12 DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)8 FixedPreciseClock (org.apache.logging.log4j.core.time.internal.FixedPreciseClock)8 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)8 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)6 LogEvent (org.apache.logging.log4j.core.LogEvent)5 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)5 IOException (java.io.IOException)4 ClockFactoryTest (org.apache.logging.log4j.core.time.ClockFactoryTest)4 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)4 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)4 SortedArrayStringMap (org.apache.logging.log4j.util.SortedArrayStringMap)4 ReusableMessageFactory (org.apache.logging.log4j.message.ReusableMessageFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1