use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class LevelPatternConverterTest method testLevelMapWithLength.
@Test
public void testLevelMapWithLength() {
final Message msg = new SimpleMessage("Hello");
LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(msg).build();
final StringBuilder sb = new StringBuilder();
LevelPatternConverter converter = LevelPatternConverter.newInstance(null);
converter.format(event, sb);
assertEquals(Level.DEBUG.toString(), sb.toString());
final String[] opts = new String[] { "WARN=Warning, length=2" };
converter = LevelPatternConverter.newInstance(opts);
sb.setLength(0);
converter.format(event, sb);
assertEquals("DE", sb.toString());
event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.WARN).setMessage(msg).build();
sb.setLength(0);
converter.format(event, sb);
assertEquals("Warning", sb.toString());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MarkerPatternConverterTest method testLookup.
@Test
public void testLookup() {
final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
final Marker eventMarker = MarkerManager.getMarker("EVENT");
final Marker auditMarker = MarkerManager.getMarker("AUDIT").setParents(eventMarker);
final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setMarker(auditMarker).setLevel(Level.DEBUG).setMessage(msg).build();
final StringBuilder sb = new StringBuilder();
final MarkerPatternConverter converter = MarkerPatternConverter.newInstance(null);
converter.format(event, sb);
assertEquals(auditMarker.toString(), sb.toString());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MarkerSimpleNamePatternConverterTest method testLookup.
@Test
public void testLookup() {
final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
final Marker eventMarker = MarkerManager.getMarker("EVENT");
final Marker auditMarker = MarkerManager.getMarker("AUDIT").setParents(eventMarker);
final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setMarker(auditMarker).setLevel(Level.DEBUG).setMessage(msg).build();
final StringBuilder sb = new StringBuilder();
final MarkerSimpleNamePatternConverter converter = MarkerSimpleNamePatternConverter.newInstance(null);
converter.format(event, sb);
assertEquals(auditMarker.getName(), sb.toString());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MaxLengthConverterTest method testOverMaxLength21WithEllipsis.
@Test
public void testOverMaxLength21WithEllipsis() {
final Message message = new SimpleMessage("012345678901234567890123456789");
final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setLevel(Level.DEBUG).setMessage(message).build();
final StringBuilder sb = new StringBuilder();
MaxLengthConverter.newInstance(null, new String[] { "%m", "21" }).format(event, sb);
assertEquals("012345678901234567890...", sb.toString());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class MaxLengthConverterTest method testUnderMaxLength.
@Test
public void testUnderMaxLength() {
final Message message = new SimpleMessage("0123456789");
final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setLevel(Level.DEBUG).setMessage(message).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
assertEquals("0123456789", sb.toString());
}
Aggregations