Search in sources :

Example 46 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class LoggerTest method testTraceWithException.

/**
     * Tests logger.trace(Object, Exception).
     */
@Test
public void testTraceWithException() {
    final ListAppender appender = new ListAppender("List");
    appender.start();
    final Logger root = Logger.getRootLogger();
    try {
        root.getLogger().addAppender(appender);
        root.setLevel(Level.INFO);
        final Logger tracer = Logger.getLogger("com.example.Tracer");
        tracer.setLevel(Level.TRACE);
        final NullPointerException ex = new NullPointerException();
        tracer.trace("Message 1", ex);
        root.trace("Discarded Message", ex);
        root.trace("Discarded Message", ex);
        final List<LogEvent> msgs = appender.getEvents();
        assertEquals(1, msgs.size());
        final LogEvent event = msgs.get(0);
        assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
        assertEquals("Message 1", event.getMessage().getFormattedMessage());
        appender.stop();
    } finally {
        root.getLogger().removeAppender(appender);
    }
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Test(org.junit.Test)

Example 47 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class LogEventEntityTest method testToImmutable_AbstractLogEventWrapperEntity.

@Test
public void testToImmutable_AbstractLogEventWrapperEntity() {
    final LogEvent logEvent = new AbstractLogEventWrapperEntity() {

        private static final long serialVersionUID = 1L;

        @Override
        public Map<String, String> getContextMap() {
            return null;
        }

        @Override
        public ContextStack getContextStack() {
            return null;
        }

        @Override
        public Level getLevel() {
            return null;
        }

        @Override
        public String getLoggerFqcn() {
            return null;
        }

        @Override
        public String getLoggerName() {
            return null;
        }

        @Override
        public Marker getMarker() {
            return null;
        }

        @Override
        public Message getMessage() {
            return null;
        }

        @Override
        public long getNanoTime() {
            return 0;
        }

        @Override
        public StackTraceElement getSource() {
            return null;
        }

        @Override
        public long getThreadId() {
            return 0;
        }

        @Override
        public String getThreadName() {
            return null;
        }

        @Override
        public int getThreadPriority() {
            return 0;
        }

        @Override
        public Throwable getThrown() {
            return null;
        }

        @Override
        public ThrowableProxy getThrownProxy() {
            return null;
        }

        @Override
        public long getTimeMillis() {
            return 0;
        }
    };
    Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) Test(org.junit.Test)

Example 48 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class LogEventEntityTest method testToImmutable_TestBaseEntity.

@Test
public void testToImmutable_TestBaseEntity() {
    final LogEvent logEvent = new TestBaseEntity();
    Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) Test(org.junit.Test)

Example 49 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class AbstractDatabaseAppenderTest method testAppend.

@Test
public void testAppend() {
    setUp("name");
    given(manager.commitAndClose()).willReturn(true);
    final LogEvent event1 = mock(LogEvent.class);
    final LogEvent event2 = mock(LogEvent.class);
    appender.append(event1);
    then(manager).should().connectAndStart();
    then(manager).should().writeInternal(same(event1));
    then(manager).should().commitAndClose();
    reset(manager);
    appender.append(event2);
    then(manager).should().connectAndStart();
    then(manager).should().writeInternal(same(event2));
    then(manager).should().commitAndClose();
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) Test(org.junit.Test)

Example 50 with LogEvent

use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.

the class AbstractDatabaseManagerTest method testBuffering01.

@Test
public void testBuffering01() throws Exception {
    setUp("name", 0);
    final LogEvent event1 = mock(LogEvent.class);
    final LogEvent event2 = mock(LogEvent.class);
    final LogEvent event3 = mock(LogEvent.class);
    manager.startup();
    then(manager).should().startupInternal();
    reset(manager);
    manager.write(event1);
    then(manager).should().connectAndStart();
    then(manager).should().writeInternal(same(event1));
    then(manager).should().commitAndClose();
    reset(manager);
    manager.write(event2);
    then(manager).should().connectAndStart();
    then(manager).should().writeInternal(same(event2));
    then(manager).should().commitAndClose();
    reset(manager);
    manager.write(event3);
    then(manager).should().connectAndStart();
    then(manager).should().writeInternal(same(event3));
    then(manager).should().commitAndClose();
    then(manager).shouldHaveNoMoreInteractions();
}
Also used : 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