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 MessageResolver method resolveString.
private static void resolveString(final String fallbackKey, final LogEvent logEvent, final JsonWriter jsonWriter) {
final Message message = logEvent.getMessage();
resolveString(fallbackKey, message, jsonWriter);
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MapResolver method toMap.
private static ReadOnlyStringMap toMap(final LogEvent logEvent) {
final Message message = logEvent.getMessage();
if (!(message instanceof MapMessage)) {
return null;
}
@SuppressWarnings("unchecked") final MapMessage<?, Object> mapMessage = (MapMessage<?, Object>) message;
return mapMessage.getIndexedReadOnlyStringMap();
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class LoggingMessageTagSupport method doEndTag.
@Override
public final int doEndTag() throws JspException {
final Log4jTaglibLogger logger = this.getLogger();
final Level level = this.getLevel();
final Marker marker = this.getMarker();
if (TagUtils.isEnabled(logger, level, marker)) {
final Object message = this.getMessage();
final Throwable exception = this.getException();
if (message instanceof Message) {
logger.logIfEnabled(FQCN, level, marker, (Message) message, exception);
} else if (message instanceof String) {
Message data;
if (this.attributes.size() > 0) {
data = logger.getMessageFactory().newMessage((String) message, this.attributes.toArray());
} else {
data = logger.getMessageFactory().newMessage((String) message);
}
logger.logIfEnabled(FQCN, level, marker, data, exception);
} else {
logger.logIfEnabled(FQCN, level, marker, logger.getMessageFactory().newMessage(message), exception);
}
}
return Tag.EVAL_PAGE;
}
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 Object p0, final Object p1, final Object p2, final Object p3, final Object p4) {
final Message msg = messageFactory.newMessage(message, p0, p1, p2, p3, p4);
logMessageSafely(fqcn, level, marker, msg, msg.getThrowable());
}
Aggregations