use of org.apache.logging.log4j.message.EntryMessage in project logging-log4j2 by apache.
the class LoggerTest method flowTracingString_SupplierOfObjectMessages.
@Test
public void flowTracingString_SupplierOfObjectMessages() {
final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<Message>() {
@Override
public Message get() {
return new ObjectMessage(1);
}
}, new Supplier<Message>() {
@Override
public Message get() {
return new ObjectMessage(2);
}
});
logger.traceExit(msg, 3);
assertEquals(2, results.size());
assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)"));
assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit"));
assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3"));
}
use of org.apache.logging.log4j.message.EntryMessage in project logging-log4j2 by apache.
the class LoggerTest method flowTracingString_SupplierOfStrings.
@Test
public void flowTracingString_SupplierOfStrings() {
final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", new Supplier<String>() {
@Override
public String get() {
return "1";
}
}, new Supplier<String>() {
@Override
public String get() {
return "2";
}
});
logger.traceExit(msg, 3);
assertEquals(2, results.size());
assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
assertThat("Missing entry data", results.get(0), containsString("doFoo(a=1, b=2)"));
assertThat("Incorrect Exit", results.get(1), startsWith("EXIT[ FLOW ] TRACE Exit"));
assertThat("Missing exit data", results.get(1), containsString("doFoo(a=1, b=2): 3"));
}
use of org.apache.logging.log4j.message.EntryMessage 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());
}
use of org.apache.logging.log4j.message.EntryMessage in project logging-log4j2 by apache.
the class AbstractLogger method entryMsg.
protected EntryMessage entryMsg(final String format, final Object... params) {
final int count = params == null ? 0 : params.length;
if (count == 0) {
if (Strings.isEmpty(format)) {
return flowMessageFactory.newEntryMessage(null);
}
return flowMessageFactory.newEntryMessage(new SimpleMessage(format));
}
if (format != null) {
return flowMessageFactory.newEntryMessage(new ParameterizedMessage(format, params));
}
final StringBuilder sb = new StringBuilder();
sb.append("params(");
for (int i = 0; i < count; i++) {
if (i > 0) {
sb.append(", ");
}
final Object parm = params[i];
sb.append(parm instanceof Message ? ((Message) parm).getFormattedMessage() : String.valueOf(parm));
}
sb.append(')');
return flowMessageFactory.newEntryMessage(new SimpleMessage(sb));
}
Aggregations