Search in sources :

Example 61 with Message

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

Example 62 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.Test)

Example 63 with Message

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

Example 64 with Message

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

Example 65 with Message

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

Aggregations

Message (org.apache.logging.log4j.message.Message)80 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)45 Test (org.junit.Test)42 LogEvent (org.apache.logging.log4j.core.LogEvent)33 Marker (org.apache.logging.log4j.Marker)23 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)22 Level (org.apache.logging.log4j.Level)17 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)14 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)14 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)13 EntryMessage (org.apache.logging.log4j.message.EntryMessage)9 StringFormattedMessage (org.apache.logging.log4j.message.StringFormattedMessage)8 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)8 Result (org.apache.logging.log4j.core.Filter.Result)7 LocalizedMessage (org.apache.logging.log4j.message.LocalizedMessage)6 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)6 IOException (java.io.IOException)5 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)5 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)5 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)5