Search in sources :

Example 21 with Marker

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

the class MarkerTest method testContainsNullMarker.

@Test
public void testContainsNullMarker() {
    final String childMarkerName = CHILD_MAKER_NAME + "-CM";
    final String parentMakerName = PARENT_MARKER_NAME + "-CM";
    final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName);
    final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName);
    slf4jMarker.add(slf4jParent);
    final Marker log4jParent = MarkerManager.getMarker(parentMakerName);
    final Marker log4jMarker = MarkerManager.getMarker(childMarkerName);
    final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent);
    final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker);
    final org.slf4j.Marker nullMarker = null;
    try {
        Assert.assertFalse(log4jSlf4jParent.contains(nullMarker));
        fail("Expected " + IllegalArgumentException.class.getName());
    } catch (final IllegalArgumentException e) {
    // expected
    }
    try {
        Assert.assertFalse(log4jSlf4jMarker.contains(nullMarker));
        fail("Expected " + IllegalArgumentException.class.getName());
    } catch (final IllegalArgumentException e) {
    // expected
    }
}
Also used : Marker(org.apache.logging.log4j.Marker) Test(org.junit.Test)

Example 22 with Marker

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

the class RingBufferLogEventTest method testGetMessageReturnsNonNullMessage.

@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;
    final long currentTimeMillis = 0;
    final long nanoTime = 1;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, currentTimeMillis, nanoTime);
    assertNotNull(evt.getMessage());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) 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 23 with Marker

use of org.apache.logging.log4j.Marker 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)

Example 24 with Marker

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

the class RingBufferLogEventTest method testSerializationDeserialization.

@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;
    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 ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(evt);
    final ObjectInputStream in = new ObjectInputStream(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(currentTimeMillis, other.getTimeMillis());
}
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) Marker(org.apache.logging.log4j.Marker) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) ContextStack(org.apache.logging.log4j.ThreadContext.ContextStack) ObjectOutputStream(java.io.ObjectOutputStream) ThrowableProxy(org.apache.logging.log4j.core.impl.ThrowableProxy) ByteArrayInputStream(java.io.ByteArrayInputStream) Level(org.apache.logging.log4j.Level) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 25 with Marker

use of org.apache.logging.log4j.Marker 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;
    final long currentTimeMillis = 0;
    final long nanoTime = 1;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, currentTimeMillis, nanoTime);
    assertEquals(Level.OFF, evt.getLevel());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) 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

Marker (org.apache.logging.log4j.Marker)50 Test (org.junit.Test)30 Message (org.apache.logging.log4j.message.Message)23 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)22 Level (org.apache.logging.log4j.Level)18 LogEvent (org.apache.logging.log4j.core.LogEvent)16 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)14 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)8 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)6 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)6 IOException (java.io.IOException)5 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)5 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)5 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)5 StringMap (org.apache.logging.log4j.util.StringMap)5 ThreadContext (org.apache.logging.log4j.ThreadContext)4 Logger (org.apache.logging.log4j.core.Logger)4 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)4 HashMap (java.util.HashMap)3 ThrowableProxy (org.apache.logging.log4j.core.impl.ThrowableProxy)3