Search in sources :

Example 21 with LogEvent

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"));
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Example 22 with LogEvent

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"));
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Example 23 with LogEvent

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());
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Example 24 with LogEvent

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());
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Example 25 with LogEvent

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());
}
Also used : AbstractLogEvent(org.apache.logging.log4j.core.AbstractLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) Test(org.junit.Test)

Aggregations

LogEvent (org.apache.logging.log4j.core.LogEvent)189 Test (org.junit.Test)150 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)127 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)94 Message (org.apache.logging.log4j.message.Message)33 Marker (org.apache.logging.log4j.Marker)16 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)11 HashMap (java.util.HashMap)9 LoggerContext (org.apache.logging.log4j.core.LoggerContext)8 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)8 File (java.io.File)7 IOException (java.io.IOException)7 Level (org.apache.logging.log4j.Level)7 Appender (org.apache.logging.log4j.core.Appender)6 MapMessage (org.apache.logging.log4j.message.MapMessage)6 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)5 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)5 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)5 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)5 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)5