use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class PatternParserTest method testPatternTruncateFromEnd.
@Test
public void testPatternTruncateFromEnd() {
final List<PatternFormatter> formatters = parser.parse(patternTruncateFromEnd);
assertNotNull(formatters);
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"org.apache.logging.log4j.PatternParserTest").setLoggerFqcn(//
Logger.class.getName()).setLevel(//
Level.INFO).setMessage(//
new SimpleMessage("Hello, world")).setThreadName(//
"Thread1").setTimeMillis(//
System.currentTimeMillis()).build();
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
final String str = buf.toString();
final String expected = "INFO org.a Hello, world" + Strings.LINE_SEPARATOR;
assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class PatternParserTest method testNestedPatternHighlight.
private void testNestedPatternHighlight(final Level level, final String expectedStart) {
final List<PatternFormatter> formatters = parser.parse(nestedPatternHighlight);
assertNotNull(formatters);
final Throwable t = new Throwable();
t.getStackTrace();
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"org.apache.logging.log4j.PatternParserTest").setMarker(//
MarkerManager.getMarker("TEST")).setLoggerFqcn(//
Logger.class.getName()).setLevel(//
level).setMessage(//
new SimpleMessage("Hello, world")).setThreadName(//
"Thread1").setSource(/*stackTraceElement[0]*/
null).setTimeMillis(//
System.currentTimeMillis()).build();
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
final String str = buf.toString();
final String expectedEnd = String.format("] %-5s: Hello, world%s[m", level, Strings.LINE_SEPARATOR);
assertTrue("Expected to start with: " + expectedStart + ". Actual: " + str, str.startsWith(expectedStart));
assertTrue("Expected to end with: \"" + expectedEnd + "\". Actual: \"" + str, str.endsWith(expectedEnd));
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class ThreadIdPatternConverterTest method testConverterAppendsLogEventNanoTimeToStringBuilder.
@Test
public void testConverterAppendsLogEventNanoTimeToStringBuilder() {
final LogEvent event = //
Log4jLogEvent.newBuilder().setThreadId(1).build();
final StringBuilder sb = new StringBuilder();
final ThreadIdPatternConverter converter = ThreadIdPatternConverter.newInstance(null);
converter.format(event, sb);
assertEquals("1", sb.toString());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class ThreadPriorityPatternConverterTest method testConverterAppendsLogEventNanoTimeToStringBuilder.
@Test
public void testConverterAppendsLogEventNanoTimeToStringBuilder() {
final LogEvent event = //
Log4jLogEvent.newBuilder().setThreadPriority(1).build();
final StringBuilder sb = new StringBuilder();
final ThreadPriorityPatternConverter converter = ThreadPriorityPatternConverter.newInstance(null);
converter.format(event, sb);
assertEquals("1", sb.toString());
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class ThrowablePatternConverterTest method testShortOptionWithSuffix.
@Test
public void testShortOptionWithSuffix() {
final String packageName = "org.apache.logging.log4j.core.pattern.";
final String[] options = { "short.className", "suffix(test suffix)" };
final ThrowablePatternConverter converter = ThrowablePatternConverter.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("Each line should end with suffix", everyLineEndsWith(result, "test suffix"));
}
Aggregations