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"));
}
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.");
}
}
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");
}
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);
}
}
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;
}
Aggregations