use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.
the class LoggerSupplierTest method flowTracing_SupplierOfObjectMessage.
@Test
public void flowTracing_SupplierOfObjectMessage() {
logger.traceEntry(new Supplier<ObjectMessage>() {
@Override
public ObjectMessage get() {
return new ObjectMessage(1234567890);
}
});
assertEquals(1, results.size());
assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
assertThat("Missing entry data", results.get(0), containsString("(1234567890)"));
assertThat("Bad toString()", results.get(0), not(containsString("ObjectMessage")));
}
use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.
the class CategoryTest method testForcedLog.
/**
* Tests Category.forcedLog.
*/
@Test
@SuppressWarnings("deprecation")
public void testForcedLog() {
final MockCategory category = new MockCategory("org.example.foo");
category.setAdditivity(false);
category.getLogger().addAppender(appender);
category.info("Hello, World");
final List<LogEvent> list = appender.getEvents();
int events = list.size();
assertTrue("Number of events should be 1, was " + events, events == 1);
LogEvent event = list.get(0);
Message msg = event.getMessage();
assertNotNull("No message", msg);
assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
Object[] objects = msg.getParameters();
assertTrue("Incorrect Object type", objects[0] instanceof String);
appender.clear();
category.log(Priority.INFO, "Hello, World");
events = list.size();
assertTrue("Number of events should be 1, was " + events, events == 1);
event = list.get(0);
msg = event.getMessage();
assertNotNull("No message", msg);
assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
objects = msg.getParameters();
assertTrue("Incorrect Object type", objects[0] instanceof String);
appender.clear();
}
use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.
the class Category method log.
public void log(final String fqcn, final Priority priority, final Object message, final Throwable t) {
if (isEnabledFor(priority)) {
final Message msg = new ObjectMessage(message);
forcedLog(fqcn, priority, msg, t);
}
}
use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.
the class Category method log.
public void log(final Priority priority, final Object message) {
if (isEnabledFor(priority)) {
final Message msg = new ObjectMessage(message);
forcedLog(FQCN, priority, msg, null);
}
}
use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.
the class Category method forcedLog.
public void forcedLog(final String fqcn, final Priority level, final Object message, final Throwable t) {
final org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
final Message msg = message instanceof Message ? (Message) message : new ObjectMessage(message);
logger.logMessage(fqcn, lvl, null, msg, t);
}
Aggregations