use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method printf.
@Override
public void printf(final Level level, final Marker marker, final String format, final Object... params) {
if (isEnabled(level, marker, format, params)) {
final Message msg = new StringFormattedMessage(format, params);
logMessageSafely(FQCN, level, marker, msg, msg.getThrowable());
}
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class StructuredDataLookupTest method testLookup.
@Test
public void testLookup() {
final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
final LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.DEBUG).setMessage(msg).build();
final StrLookup lookup = new StructuredDataLookup();
String value = lookup.lookup(event, TESTKEY);
assertEquals(TESTVAL, value);
value = lookup.lookup("BadKey");
assertNull(value);
}
use of org.apache.logging.log4j.message.Message 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.Message 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.Message 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);
}
}
Aggregations