Search in sources :

Example 1 with FlowMessageFactory

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

the class TraceLoggingTest method testTraceEntryExit.

@Test
public void testTraceEntryExit() {
    currentLevel = Level.TRACE;
    final FlowMessageFactory fact = new DefaultFlowMessageFactory();
    final ParameterizedMessage paramMsg = new ParameterizedMessage("Tracy {}", "Logan");
    currentEvent = new LogEvent(ENTRY_MARKER.getName(), fact.newEntryMessage(paramMsg), null);
    final EntryMessage entry = traceEntry("Tracy {}", "Logan");
    final ReusableParameterizedMessage msg = ReusableParameterizedMessageTest.set(new ReusableParameterizedMessage(), "Tracy {}", "Logan");
    ReusableParameterizedMessageTest.set(msg, "Some other message {}", 123);
    currentEvent = new LogEvent(null, msg, null);
    trace("Some other message {}", 123);
    // ensure original entry message not overwritten
    assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
    currentEvent = new LogEvent(EXIT_MARKER.getName(), fact.newExitMessage(entry), null);
    traceExit(entry);
    // ensure original entry message not overwritten
    assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
}
Also used : FlowMessageFactory(org.apache.logging.log4j.message.FlowMessageFactory) DefaultFlowMessageFactory(org.apache.logging.log4j.message.DefaultFlowMessageFactory) DefaultFlowMessageFactory(org.apache.logging.log4j.message.DefaultFlowMessageFactory) ReusableParameterizedMessage(org.apache.logging.log4j.message.ReusableParameterizedMessage) ReusableParameterizedMessage(org.apache.logging.log4j.message.ReusableParameterizedMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EntryMessage(org.apache.logging.log4j.message.EntryMessage) ReusableParameterizedMessageTest(org.apache.logging.log4j.message.ReusableParameterizedMessageTest) Test(org.junit.Test)

Example 2 with FlowMessageFactory

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

the class TraceLoggingTest method testTraceEntryMessage.

@Test
public void testTraceEntryMessage() {
    currentLevel = Level.TRACE;
    final FlowMessageFactory fact = new DefaultFlowMessageFactory();
    final ParameterizedMessage paramMsg = new ParameterizedMessage("Tracy {}", "Logan");
    currentEvent = new LogEvent(ENTRY_MARKER.getName(), fact.newEntryMessage(paramMsg), null);
    final ReusableParameterizedMessage msg = ReusableParameterizedMessageTest.set(new ReusableParameterizedMessage(), "Tracy {}", "Logan");
    final EntryMessage entry = traceEntry(msg);
    ReusableParameterizedMessageTest.set(msg, "Some other message {}", 123);
    currentEvent = new LogEvent(null, msg, null);
    trace("Some other message {}", 123);
    // ensure original entry message not overwritten
    assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
    currentEvent = new LogEvent(EXIT_MARKER.getName(), fact.newExitMessage(entry), null);
    traceExit(entry);
    // ensure original entry message not overwritten
    assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
}
Also used : FlowMessageFactory(org.apache.logging.log4j.message.FlowMessageFactory) DefaultFlowMessageFactory(org.apache.logging.log4j.message.DefaultFlowMessageFactory) DefaultFlowMessageFactory(org.apache.logging.log4j.message.DefaultFlowMessageFactory) ReusableParameterizedMessage(org.apache.logging.log4j.message.ReusableParameterizedMessage) ReusableParameterizedMessage(org.apache.logging.log4j.message.ReusableParameterizedMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EntryMessage(org.apache.logging.log4j.message.EntryMessage) ReusableParameterizedMessageTest(org.apache.logging.log4j.message.ReusableParameterizedMessageTest) Test(org.junit.Test)

Aggregations

DefaultFlowMessageFactory (org.apache.logging.log4j.message.DefaultFlowMessageFactory)2 EntryMessage (org.apache.logging.log4j.message.EntryMessage)2 FlowMessageFactory (org.apache.logging.log4j.message.FlowMessageFactory)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 ReusableParameterizedMessage (org.apache.logging.log4j.message.ReusableParameterizedMessage)2 ReusableParameterizedMessageTest (org.apache.logging.log4j.message.ReusableParameterizedMessageTest)2 Test (org.junit.Test)2