Search in sources :

Example 66 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class BracketInNotInterpolatedMessageTest method noInterpolation.

@Test
public void noInterpolation() {
    final Logger logger = Logger.getLogger("Test");
    logger.info("{raw}");
    // should lead to the same as previous but was not the case LOG4J2-1251
    logger.log(new LogRecord(INFO, "{raw}"));
    final List<LogEvent> events = ListAppender.getListAppender("TestAppender").getEvents();
    assertThat(events, hasSize(2));
    assertEquals("{raw}", events.get(0).getMessage().getFormattedMessage());
    assertEquals("{raw}", events.get(1).getMessage().getFormattedMessage());
}
Also used : LogRecord(java.util.logging.LogRecord) LogEvent(org.apache.logging.log4j.core.LogEvent) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 67 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class AbstractLoggerTest method testLogParamMarkers.

@Test
public void testLogParamMarkers() {
    final Logger flowLogger = Logger.getLogger("TestFlow");
    flowLogger.logp(java.util.logging.Level.FINER, "sourceClass", "sourceMethod", "ENTER {0}", "params");
    final List<LogEvent> events = flowAppender.getEvents();
    assertEquals("ENTER params", events.get(0).getMessage().getFormattedMessage());
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 68 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class AbstractStringLayout method serializeToString.

protected String serializeToString(final Serializer serializer) {
    if (serializer == null) {
        return null;
    }
    final LoggerConfig rootLogger = getConfiguration().getRootLogger();
    // Using "" for the FQCN, does it matter?
    final LogEvent logEvent = getLogEventFactory().createEvent(rootLogger.getName(), null, Strings.EMPTY, rootLogger.getLevel(), null, null, null);
    return serializer.toSerializable(logEvent);
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 69 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class MapRewritePolicyTest method defaultIsAdd.

@Test
public void defaultIsAdd() {
    final MapRewritePolicy addPolicy = MapRewritePolicy.createPolicy(null, rewrite);
    LogEvent rewritten = addPolicy.rewrite(logEvent0);
    compareLogEvents(logEvent0, rewritten);
    assertEquals("Simple log message changed", logEvent0.getMessage(), rewritten.getMessage());
    rewritten = addPolicy.rewrite(logEvent1);
    compareLogEvents(logEvent1, rewritten);
    checkAdded(((MapMessage) rewritten.getMessage()).getData());
    rewritten = addPolicy.rewrite(logEvent2);
    compareLogEvents(logEvent2, rewritten);
    checkAdded(((MapMessage) rewritten.getMessage()).getData());
    rewritten = addPolicy.rewrite(logEvent3);
    compareLogEvents(logEvent3, rewritten);
    checkAdded(((MapMessage) rewritten.getMessage()).getData());
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) Test(org.junit.Test)

Example 70 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class MapLookupTest method testEventMapMessage.

@Test
public void testEventMapMessage() {
    final HashMap<String, String> map = new HashMap<>();
    map.put("A", "B");
    final HashMap<String, String> eventMap = new HashMap<>();
    eventMap.put("A1", "B1");
    final MapMessage message = new MapMessage(eventMap);
    final LogEvent event = Log4jLogEvent.newBuilder().setMessage(message).build();
    final MapLookup lookup = new MapLookup(map);
    assertEquals("B", lookup.lookup(event, "A"));
    assertEquals("B1", lookup.lookup(event, "A1"));
}
Also used : HashMap(java.util.HashMap) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) MapMessage(org.apache.logging.log4j.message.MapMessage) Test(org.junit.Test)

Aggregations

LogEvent (org.apache.logging.log4j.core.LogEvent)188 Test (org.junit.Test)150 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)127 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)94 Message (org.apache.logging.log4j.message.Message)33 Marker (org.apache.logging.log4j.Marker)16 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)11 HashMap (java.util.HashMap)9 LoggerContext (org.apache.logging.log4j.core.LoggerContext)8 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)8 File (java.io.File)7 IOException (java.io.IOException)7 Level (org.apache.logging.log4j.Level)7 MapMessage (org.apache.logging.log4j.message.MapMessage)6 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)5 Appender (org.apache.logging.log4j.core.Appender)5 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)5 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)5 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)5 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)5