use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class ExtendedThrowablePatternConverterTest method testSuffixFromNormalPattern.
@Test
public void testSuffixFromNormalPattern() {
final String suffix = "suffix(%mdc{key})";
ThreadContext.put("key", "test suffix ");
final String[] options = { suffix };
final ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null, options);
final Throwable cause = new NullPointerException("null pointer");
final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"testLogger").setLoggerFqcn(//
this.getClass().getName()).setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("test exception")).setThrown(parent).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String result = sb.toString();
assertTrue("No suffix", result.contains("test suffix"));
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class ExtendedThrowablePatternConverterTest method testSuffix.
@Test
public void testSuffix() {
final String suffix = "suffix(test suffix)";
final String[] options = { suffix };
final ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null, options);
final Throwable cause = new NullPointerException("null pointer");
final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"testLogger").setLoggerFqcn(//
this.getClass().getName()).setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("test exception")).setThrown(parent).build();
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String result = sb.toString();
assertTrue("No suffix", result.contains("test suffix"));
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class HighlightConverterTest method testAnsiEmpty.
@Test
public void testAnsiEmpty() {
final String[] options = { "", PatternParser.NO_CONSOLE_NO_ANSI + "=false, " + PatternParser.DISABLE_ANSI + "=false" };
final HighlightConverter converter = HighlightConverter.newInstance(null, options);
final LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("a.b.c").setMessage(new SimpleMessage("message in a bottle")).build();
final StringBuilder buffer = new StringBuilder();
converter.format(event, buffer);
assertEquals("", buffer.toString());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class HighlightConverterTest method testNoAnsiEmpty.
@Test
public void testNoAnsiEmpty() {
final String[] options = { "", PatternParser.DISABLE_ANSI + "=true" };
final HighlightConverter converter = HighlightConverter.newInstance(null, options);
final LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("a.b.c").setMessage(new SimpleMessage("message in a bottle")).build();
final StringBuilder buffer = new StringBuilder();
converter.format(event, buffer);
assertEquals("", buffer.toString());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class DatePatternConverterTest method testFormatLogEventStringBuilderIso8601.
@Test
public void testFormatLogEventStringBuilderIso8601() {
final LogEvent event = new MyLogEvent();
final DatePatternConverter converter = DatePatternConverter.newInstance(ISO8601_FORMAT_OPTIONS);
final StringBuilder sb = new StringBuilder();
converter.format(event, sb);
final String expected = "2011-12-30T10:56:35,987";
assertEquals(expected, sb.toString());
}
Aggregations