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
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations