use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MessageResolverTest method test_message_fallbackKey.
@Test
void test_message_fallbackKey() {
// Create the event template.
final String eventTemplate = writeJson(asMap("message", asMap("$resolver", "message", "fallbackKey", "formattedMessage")));
// Create the layout.
final JsonTemplateLayout layout = JsonTemplateLayout.newBuilder().setConfiguration(CONFIGURATION).setEventTemplate(eventTemplate).build();
// Create a log event with a MapMessage.
final Message mapMessage = new StringMapMessage().with("key1", "val1");
final LogEvent mapMessageLogEvent = Log4jLogEvent.newBuilder().setMessage(mapMessage).setTimeMillis(System.currentTimeMillis()).build();
// Check the serialized MapMessage.
usingSerializedLogEventAccessor(layout, mapMessageLogEvent, accessor -> assertThat(accessor.getString(new String[] { "message", "key1" })).isEqualTo("val1"));
// Create a log event with a SimpleMessage.
final Message simpleMessage = new SimpleMessage("simple");
final LogEvent simpleMessageLogEvent = Log4jLogEvent.newBuilder().setMessage(simpleMessage).setTimeMillis(System.currentTimeMillis()).build();
// Check the serialized MapMessage.
usingSerializedLogEventAccessor(layout, simpleMessageLogEvent, accessor -> assertThat(accessor.getString(new String[] { "message", "formattedMessage" })).isEqualTo("simple"));
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class ReadOnlyStringMapResolverTest method test_map_key_access.
@Test
public void test_map_key_access() {
// Create the log event.
final String directlyAccessedKey = "mapKey1";
final String directlyAccessedValue = "mapValue1";
final String directlyAccessedNullPropertyKey = "mapKey2";
final Message message = new StringMapMessage().with(directlyAccessedKey, directlyAccessedValue);
final LogEvent logEvent = Log4jLogEvent.newBuilder().setMessage(message).build();
// Check the serialized event.
testReadOnlyStringMapKeyAccess(directlyAccessedKey, directlyAccessedValue, directlyAccessedNullPropertyKey, logEvent, "map");
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method logMessage.
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
final Message msg = messageFactory.newMessage(message, LambdaUtil.getAll(paramSuppliers));
logMessageSafely(fqcn, level, marker, msg, msg.getThrowable());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method logMessage.
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message) {
final Message msg = messageFactory.newMessage(message);
logMessageSafely(fqcn, level, marker, msg, msg.getThrowable());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class AbstractLogger method logMessage.
protected void logMessage(final String fqcn, final Level level, final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
final Message message = LambdaUtil.get(msgSupplier);
logMessageSafely(fqcn, level, marker, message, (t == null && message != null) ? message.getThrowable() : t);
}
Aggregations