Search in sources :

Example 1 with ReusableSimpleMessage

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

the class SmtpManagerTest method getReusableMessage.

private ReusableMessage getReusableMessage(String text) {
    ReusableSimpleMessage message = new ReusableSimpleMessage();
    message.set(text);
    return message;
}
Also used : ReusableSimpleMessage(org.apache.logging.log4j.message.ReusableSimpleMessage)

Example 2 with ReusableSimpleMessage

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

the class MutableLogEventTest method testClear.

@Test
public void testClear() {
    final MutableLogEvent mutable = new MutableLogEvent();
    // initialize the event with an empty message
    ReusableSimpleMessage simpleMessage = new ReusableSimpleMessage();
    simpleMessage.set("");
    mutable.setMessage(simpleMessage);
    assertEquals(0, mutable.getContextData().size(), "context data");
    assertNull(mutable.getContextStack(), "context stack");
    assertFalse(mutable.isEndOfBatch(), "end of batch");
    assertFalse(mutable.isIncludeLocation(), "incl loc");
    assertSame(Level.OFF, mutable.getLevel(), "level");
    assertNull(mutable.getLoggerFqcn(), "fqcn");
    assertNull(mutable.getLoggerName(), "logger");
    assertNull(mutable.getMarker(), "marker");
    assertEquals(mutable, mutable.getMessage(), "msg");
    assertEquals(0, mutable.getNanoTime(), "nanoTm");
    assertEquals(0, mutable.getThreadId(), "tid");
    assertNull(mutable.getThreadName(), "tname");
    assertEquals(0, mutable.getThreadPriority(), "tpriority");
    assertNull(mutable.getThrown(), "thrwn");
    assertEquals(0, mutable.getTimeMillis(), "timeMs");
    assertNull(mutable.getSource(), "source");
    assertNull(mutable.getThrownProxy(), "thrownProxy");
    mutable.setContextData(CONTEXT_DATA);
    mutable.setContextStack(STACK);
    mutable.setEndOfBatch(true);
    mutable.setIncludeLocation(true);
    mutable.setLevel(Level.WARN);
    mutable.setLoggerFqcn(getClass().getName());
    mutable.setLoggerName("loggername");
    mutable.setMarker(MarkerManager.getMarker("marked man"));
    mutable.setMessage(new ParameterizedMessage("message in a {}", "bottle"));
    mutable.setNanoTime(1234);
    mutable.setThreadId(987);
    mutable.setThreadName("ito");
    mutable.setThreadPriority(9);
    mutable.setThrown(new Exception());
    mutable.setTimeMillis(56789);
    assertNotNull(mutable.getContextStack(), "context stack");
    assertTrue(mutable.isEndOfBatch(), "end of batch");
    assertTrue(mutable.isIncludeLocation(), "incl loc");
    assertNotNull(mutable.getLevel(), "level");
    assertNotNull(mutable.getLoggerFqcn(), "fqcn");
    assertNotNull(mutable.getLoggerName(), "logger");
    assertNotNull(mutable.getMarker(), "marker");
    assertEquals(new ParameterizedMessage("message in a {}", "bottle"), mutable.getMessage(), "msg");
    assertNotEquals(0, mutable.getNanoTime(), "nanoTm");
    assertNotEquals(0, mutable.getThreadId(), "tid");
    assertNotNull(mutable.getThreadName(), "tname");
    assertNotEquals(0, mutable.getThreadPriority(), "tpriority");
    assertNotNull(mutable.getThrown(), "thrwn");
    assertNotEquals(0, mutable.getTimeMillis(), "timeMs");
    assertNotNull(mutable.getSource(), "source");
    assertNotNull(mutable.getThrownProxy(), "thrownProxy");
    mutable.clear();
    assertEquals(0, mutable.getContextData().size(), "context map");
    assertNull(mutable.getContextStack(), "context stack");
    assertSame(Level.OFF, mutable.getLevel(), "level");
    assertNull(mutable.getLoggerFqcn(), "fqcn");
    assertNull(mutable.getLoggerName(), "logger");
    assertNull(mutable.getMarker(), "marker");
    assertEquals(mutable, mutable.getMessage(), "msg");
    assertNull(mutable.getThrown(), "thrwn");
    assertNull(mutable.getSource(), "source");
    assertNull(mutable.getThrownProxy(), "thrownProxy");
    // primitive fields are NOT reset:
    assertTrue(mutable.isEndOfBatch(), "end of batch");
    assertTrue(mutable.isIncludeLocation(), "incl loc");
    assertNotEquals(0, mutable.getNanoTime(), "nanoTm");
    assertNotEquals(0, mutable.getTimeMillis(), "timeMs");
    // thread-local fields are NOT reset:
    assertNotEquals(0, mutable.getThreadId(), "tid");
    assertNotNull(mutable.getThreadName(), "tname");
    assertNotEquals(0, mutable.getThreadPriority(), "tpriority");
}
Also used : ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ReusableSimpleMessage(org.apache.logging.log4j.message.ReusableSimpleMessage) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

ReusableSimpleMessage (org.apache.logging.log4j.message.ReusableSimpleMessage)2 IOException (java.io.IOException)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 Test (org.junit.jupiter.api.Test)1