Search in sources :

Example 41 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.

the class SymRollingFileAppenderTest method testCacheExceeded.

@Test
public void testCacheExceeded() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    SymRollingFileAppender appender = getAppenderForTest(os);
    final int HISTORY_SIZE = 100;
    final int TEST_TOTAL = HISTORY_SIZE * 4;
    appender.setHistorySize(HISTORY_SIZE);
    for (int i = 0; i < TEST_TOTAL; i++) {
        Exception ex = new Exception("Test exception." + i);
        LoggingEvent event = getLoggingEventForTest("Test Exception.", ex);
        appender.append(event);
        LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
        appender.append(event1);
    }
    String logging = os.toString("UTF8");
    assertEquals(TEST_TOTAL, StringUtils.countMatches(logging, "StackTraceKey.init"));
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 42 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.

the class SymRollingFileAppenderTest method testDuplicatedLogMessages.

@Test
public void testDuplicatedLogMessages() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    SymRollingFileAppender appender = getAppenderForTest(os);
    Exception ex = new Exception("Test exception.");
    LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
    LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex);
    LoggingEvent event3 = getLoggingEventForTest("Test Exception.", ex);
    appender.append(event1);
    appender.append(event2);
    appender.append(event3);
    String logging = os.toString("UTF8");
    // 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
    Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
    Matcher m = initPattern.matcher(logging);
    if (m.matches()) {
        String stackTraceKey = "Exception:" + m.group(1);
        assertEquals(3, StringUtils.countMatches(logging, stackTraceKey));
    } else {
        fail("Didn't find proper logging pattern.");
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 43 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project gerrit by GerritCodeReview.

the class SshLog method onLogout.

void onLogout() {
    LoggingEvent entry = log("LOGOUT");
    if (async != null) {
        async.append(entry);
    }
    audit(context.get(), "0", "LOGOUT");
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Example 44 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project JMRI by JMRI.

the class JUnitAppender method end.

/**
     * Tell appender that the JUnit test is ended.
     * <P>
     * Any queued messages at this point will be passed through to the actual
     * log.
     */
public static void end() {
    hold = false;
    while (!list.isEmpty()) {
        LoggingEvent evt = list.remove(0);
        instance().superappend(evt);
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Example 45 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project JMRI by JMRI.

the class JUnitAppender method clearBacklog.

/**
     * Remove any messages stored up, returning how many there were. This is
     * used to skip over messages that don't matter, e.g. during setting up a
     * test. Removed messages are not sent for further logging.
     *
     * @param level lowest level counted in return value, e.g. WARN means WARN
     *              and higher will be counted
     * @return count of skipped messages
     * @see #clearBacklog()
     */
public static int clearBacklog(Level level) {
    if (list.isEmpty()) {
        return 0;
    }
    int retval = 0;
    for (LoggingEvent event : list) {
        if (event != null && event.getLevel() != null && event.getLevel().toInt() >= level.toInt()) {
            // higher number -> more severe, specific, limited
            retval++;
        }
    // with Log4J 2, this could have used isMoreSpecificThan(level)
    }
    list.clear();
    return retval;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Aggregations

LoggingEvent (org.apache.log4j.spi.LoggingEvent)48 Test (org.junit.Test)21 Logger (org.apache.log4j.Logger)12 Pattern (java.util.regex.Pattern)7 Matcher (java.util.regex.Matcher)6 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)6 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)3 LoggingException (com.axway.ats.log.autodb.exceptions.LoggingException)2 AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)2 IOException (java.io.IOException)2 Appender (org.apache.log4j.Appender)2 Category (org.apache.log4j.Category)2 Level (org.apache.log4j.Level)2 Filter (org.apache.log4j.spi.Filter)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 InsertMessageEvent (com.axway.ats.log.autodb.events.InsertMessageEvent)1 CacheableEvent (com.axway.ats.log.autodb.model.CacheableEvent)1 SystemLogLevel (com.axway.ats.log.model.SystemLogLevel)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1