Search in sources :

Example 6 with ObjectMessage

use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.

the class LoggerSupplierTest method flowTracing_SupplierOfObjectMessage.

@Test
public void flowTracing_SupplierOfObjectMessage() {
    logger.traceEntry(new Supplier<ObjectMessage>() {

        @Override
        public ObjectMessage get() {
            return new ObjectMessage(1234567890);
        }
    });
    assertEquals(1, results.size());
    assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
    assertThat("Missing entry data", results.get(0), containsString("(1234567890)"));
    assertThat("Bad toString()", results.get(0), not(containsString("ObjectMessage")));
}
Also used : ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) Test(org.junit.Test)

Example 7 with ObjectMessage

use of org.apache.logging.log4j.message.ObjectMessage 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 8 with ObjectMessage

use of org.apache.logging.log4j.message.ObjectMessage 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 9 with ObjectMessage

use of org.apache.logging.log4j.message.ObjectMessage 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)

Example 10 with ObjectMessage

use of org.apache.logging.log4j.message.ObjectMessage in project logging-log4j2 by apache.

the class Category method forcedLog.

public void forcedLog(final String fqcn, final Priority level, final Object message, final Throwable t) {
    final org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
    final Message msg = message instanceof Message ? (Message) message : new ObjectMessage(message);
    logger.logMessage(fqcn, lvl, null, 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)

Aggregations

ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)10 Message (org.apache.logging.log4j.message.Message)8 Test (org.junit.Test)5 LocalizedMessage (org.apache.logging.log4j.message.LocalizedMessage)4 Marker (org.apache.logging.log4j.Marker)2 LogEvent (org.apache.logging.log4j.core.LogEvent)2 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 SimpleBindings (javax.script.SimpleBindings)1 Level (org.apache.logging.log4j.Level)1 Logger (org.apache.logging.log4j.Logger)1 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)1 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)1 EntryMessage (org.apache.logging.log4j.message.EntryMessage)1 JsonMessage (org.apache.logging.log4j.message.JsonMessage)1 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)1 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)1 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)1