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());
}
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());
}
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);
}
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());
}
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"));
}
Aggregations