Search in sources :

Example 91 with Message

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);
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Message(org.apache.logging.log4j.message.Message) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) Test(org.junit.jupiter.api.Test)

Example 92 with Message

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);
}
Also used : MultiformatMessage(org.apache.logging.log4j.message.MultiformatMessage) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) MapMessage(org.apache.logging.log4j.message.MapMessage) Message(org.apache.logging.log4j.message.Message) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage)

Example 93 with Message

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();
}
Also used : MapMessage(org.apache.logging.log4j.message.MapMessage) Message(org.apache.logging.log4j.message.Message) MapMessage(org.apache.logging.log4j.message.MapMessage)

Example 94 with Message

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;
}
Also used : Message(org.apache.logging.log4j.message.Message) Level(org.apache.logging.log4j.Level) Marker(org.apache.logging.log4j.Marker)

Example 95 with Message

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());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Message(org.apache.logging.log4j.message.Message) EntryMessage(org.apache.logging.log4j.message.EntryMessage) StringFormattedMessage(org.apache.logging.log4j.message.StringFormattedMessage)

Aggregations

Message (org.apache.logging.log4j.message.Message)128 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)88 LogEvent (org.apache.logging.log4j.core.LogEvent)55 Test (org.junit.jupiter.api.Test)50 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)46 Marker (org.apache.logging.log4j.Marker)26 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)26 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)24 Level (org.apache.logging.log4j.Level)23 Test (org.junit.Test)22 StringMapMessage (org.apache.logging.log4j.message.StringMapMessage)19 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)18 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)17 MapMessage (org.apache.logging.log4j.message.MapMessage)15 StringMap (org.apache.logging.log4j.util.StringMap)15 DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)9 EntryMessage (org.apache.logging.log4j.message.EntryMessage)9 Map (java.util.Map)8 StringFormattedMessage (org.apache.logging.log4j.message.StringFormattedMessage)8 IOException (java.io.IOException)7