use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class MaxLengthConverterTest method testOverMaxLength.
@Test
public void testOverMaxLength() throws Exception {
final Message message = new SimpleMessage("01234567890123456789");
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());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class MdcPatternConverterTest method testConverterWithKeys.
@Test
public void testConverterWithKeys() {
final Message msg = new SimpleMessage("Hello");
final String[] options = new String[] { "object, subject" };
final MdcPatternConverter converter = MdcPatternConverter.newInstance(options);
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(//
msg).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String str = sb.toString();
final String expected = "{object=Log4j, subject=I}";
assertEquals(expected, str);
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class MdcPatternConverterTest method testConverterWithKey.
@Test
public void testConverterWithKey() {
final Message msg = new SimpleMessage("Hello");
final String[] options = new String[] { "object" };
final MdcPatternConverter converter = MdcPatternConverter.newInstance(options);
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(//
msg).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String str = sb.toString();
final String expected = "Log4j";
assertEquals(expected, str);
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class MdcPatternConverterTest method testConverter.
@Test
public void testConverter() {
final Message msg = new SimpleMessage("Hello");
final MdcPatternConverter converter = MdcPatternConverter.newInstance(null);
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(//
msg).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String str = sb.toString();
final String expected = "{object=Log4j, subject=I, verb=love}";
assertTrue("Incorrect result. Expected " + expected + ", actual " + str, str.equals(expected));
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class MessagePatternConverterTest method testPatternWithConfiguration.
@Test
public void testPatternWithConfiguration() throws Exception {
final Configuration config = new DefaultConfiguration();
final MessagePatternConverter converter = MessagePatternConverter.newInstance(config, null);
Message msg = new SimpleMessage("Hello!");
LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(msg).build();
StringBuilder sb = new StringBuilder();
converter.format(event, sb);
assertEquals("Unexpected result", "Hello!", sb.toString());
event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(null).build();
sb = new StringBuilder();
converter.format(event, sb);
assertEquals("Incorrect length: " + sb, 0, sb.length());
msg = new SimpleMessage(null);
event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"MyLogger").setLevel(//
Level.DEBUG).setMessage(msg).build();
sb = new StringBuilder();
converter.format(event, sb);
assertEquals("Incorrect length: " + sb, 4, sb.length());
}
Aggregations