Search in sources :

Example 1 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter in project ACS by ACS-Community.

the class FilterTypePanel method getFilter.

/* (non-Javadoc)
	 * @see com.cosylab.logging.settings.FilterParameterPanel#getFilter()
	 */
public Filter getFilter() throws FilterParameterException {
    boolean bmin = minimumCheck.isSelected();
    boolean bmax = maximumCheck.isSelected();
    boolean bexact = exactCheck.isSelected();
    LogTypeHelper min = null;
    LogTypeHelper max = null;
    if (bexact) {
        try {
            return new ExactFilter(getFieldIndex(), isLethal(), (LogTypeHelper) exact.getSelectedItem(), notCheck.isSelected());
        } catch (InvalidFilterConstraintException e) {
            e.printStackTrace();
            throw new FilterParameterException(e.getMessage());
        }
    }
    if (bmin) {
        min = (LogTypeHelper) minimum.getSelectedItem();
    }
    if (bmax) {
        max = (LogTypeHelper) maximum.getSelectedItem();
    }
    if ((min != null) && (max != null)) {
        if (min.compareTo(max) > -1) {
            throw new FilterParameterException("Minimum must be less than maximum");
        }
    }
    try {
        return new MinMaxFilter(getFieldIndex(), isLethal(), min, max, notCheck.isSelected());
    } catch (InvalidFilterConstraintException e) {
        throw new FilterParameterException(e.getMessage());
    }
}
Also used : MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) ExactFilter(com.cosylab.logging.engine.ExactFilter) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) InvalidFilterConstraintException(com.cosylab.logging.engine.InvalidFilterConstraintException)

Example 2 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter in project ACS by ACS-Community.

the class FiltersVectorTest method testHasActiveFilters.

/**
	 * Test {@link FiltersVector#hasActiveFilters()}
	 */
public void testHasActiveFilters() throws Exception {
    //No active filters yet
    assertFalse("The vector should be empty at startup", filters.hasActiveFilters());
    Filter exactLogMessageFilter = new ExactFilter(LogField.LOGMESSAGE, lethal, "A message", false);
    filters.addFilter(exactLogMessageFilter, false);
    assertFalse("The vector should contain one filter but not active", filters.hasActiveFilters());
    Filter stackLvlFilter = new ExactFilter(LogField.STACKLEVEL, lethal, Integer.valueOf(5), false);
    filters.addFilter(stackLvlFilter, true);
    assertTrue("The vector should contain one active filter", filters.hasActiveFilters());
    filters.clear();
    assertFalse("The empty vector has no active filters", filters.hasActiveFilters());
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) RegExpFilter(com.cosylab.logging.engine.RegExpFilter) ExactFilter(com.cosylab.logging.engine.ExactFilter) MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) Filter(com.cosylab.logging.engine.Filter)

Example 3 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter in project ACS by ACS-Community.

the class EngineFilteringTest method testFiltering.

/**
	 * Set a filter and checks if the logs received are those passing a filters.
	 * <P>
	 * In this case we do not need to check the correctness of the logs received 
	 * in the listeners but only if they are received or not because it means that
	 * the engine is using the filters.
	 * <P>
	 * For this example, the test defines 1 filter based on the type of the logs.
	 * <P>
	 * The correctness of the filtering is also tested in another test because the engine 
	 * uses the same filters used by the table.
	 * 
	 * @throws Exception
	 */
public void testFiltering() throws Exception {
    // Randomly generate the logs
    Collection<ILogEntry> logs = CacheUtils.generateLogs(NUMBER_OF_LOGS);
    assertNotNull(logs);
    assertEquals(NUMBER_OF_LOGS, logs.size());
    Collection<ILogEntry> flushLogs = CacheUtils.generateLogsType(100, LogTypeHelper.NOTICE);
    // Create a filter for the type INFO
    Filter f = new ExactFilter(LogField.ENTRYTYPE, false, LogTypeHelper.INFO, false);
    assertNotNull(f);
    // And a filter for the source name
    Filter nameFilter = new ExactFilter(LogField.ROUTINE, false, getName(), false);
    assertNotNull(nameFilter);
    // No filters exists in the engine
    assertNull(engine.getFilters());
    // Add the filters
    engine.addFilter(f);
    engine.addFilter(nameFilter);
    assertNotNull(engine.getFilters());
    assertEquals("Size differ", 2, engine.getFilters().size());
    // connect the engine
    engine.connect();
    // wait until the engine is connected
    int iterCount = 0;
    while (iterCount < TIMEOUT && !engine.isConnected()) {
        iterCount++;
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
    }
    assertTrue(engine.isConnected());
    // publish all the logs and count the number of INFO logs
    int infos = 0;
    for (ILogEntry log : logs) {
        AcsLogLevel level = AcsLogLevel.fromAcsCoreLevel(log.getType().acsCoreLevel);
        m_logger.log(level, (String) log.getField(LogField.LOGMESSAGE));
        if (log.getType() == LogTypeHelper.INFO) {
            infos++;
        }
    }
    // If it is possible then it is better this second option then sending logs..
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Flushing");
    for (ILogEntry log : flushLogs) {
        AcsLogLevel level = AcsLogLevel.fromAcsCoreLevel(log.getType().acsCoreLevel);
        m_logger.log(level, (String) log.getField(LogField.LOGMESSAGE));
    }
    // wait till all the logs are received
    //
    // It additionally waits for TIMEOUT seconds after the last log has been 
    // received to be sure there are no further logs delayed because of caching
    // or similar problems
    // The number of seconds after the last log has been received
    int elapsed = 0;
    // The number of logs at the previous iteration
    int count = 0;
    while (elapsed < TIMEOUT) {
        synchronized (receivedLogs) {
            if (receivedLogs.size() != count) {
                count = receivedLogs.size();
                elapsed = 0;
                continue;
            }
        }
        // No new logs received
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
        elapsed++;
    }
    // If all the logs have been received then xmlLogsCount must be greater then NUMBER_OF_LOGS
    // Not equal because the xml logs are not filtered and there can be logs generated
    // outside of this object
    assertTrue("Received only " + xmlLogsCount.get() + " xml logs, when there should have been at least " + NUMBER_OF_LOGS, xmlLogsCount.get() >= NUMBER_OF_LOGS);
    // Check if the number of received logs is as expected
    assertEquals(infos, receivedLogs.size());
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ExactFilter(com.cosylab.logging.engine.ExactFilter) Filter(com.cosylab.logging.engine.Filter) AcsLogLevel(alma.acs.logging.AcsLogLevel)

Example 4 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter in project ACS by ACS-Community.

the class EngineFilteringTest method testAddFilter.

/**
	 * Test the adding and clearing filters
	 * 
	 * @throws Exception
	 */
public void testAddFilter() throws Exception {
    // No filters defined: getFilters() return null
    assertNull(engine.getFilters());
    // Create a filter
    Filter f = new ExactFilter(LogField.ENTRYTYPE, false, LogTypeHelper.INFO, false);
    assertNotNull(f);
    // Add the filter
    engine.addFilter(f);
    assertNotNull(engine.getFilters());
    assertEquals("Sizes differ", 1, engine.getFilters().size());
    // The filters has been added as active
    assertTrue(engine.getFilters().hasActiveFilters());
    // Create and add another filter
    Filter f2 = new ExactFilter(LogField.ENTRYTYPE, false, LogTypeHelper.DEBUG, false);
    assertNotNull(f2);
    assertEquals("Sizes differ", 1, engine.getFilters().size());
    // Clear the filters
    engine.clearFilters();
    assertNull(engine.getFilters());
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) ExactFilter(com.cosylab.logging.engine.ExactFilter) Filter(com.cosylab.logging.engine.Filter)

Example 5 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter in project ACS by ACS-Community.

the class FilterTest method testExactLogType.

/**
	 * Check if the filter works for exact value of log type.
	 */
public void testExactLogType() throws Exception {
    // Test the LogMessgae
    String logMessageToTest = "A message for a log";
    Filter exactLogMessageFilter = new ExactFilter(LogField.LOGMESSAGE, lethal, logMessageToTest, false);
    assertTrue("Exact filetrs should have accepted this log msg", exactLogMessageFilter.applyTo(log1, lethal));
    String anotherLogMessage = "Another message";
    Filter noExactLogMessageFilter = new ExactFilter(LogField.LOGMESSAGE, lethal, anotherLogMessage, false);
    assertFalse("Exact filetrs should have discarded this log msg", noExactLogMessageFilter.applyTo(log1, lethal));
    // Test the file name
    String fileName = "File.java";
    Filter exactfileNameFilter = new ExactFilter(LogField.FILE, lethal, fileName, false);
    assertTrue("Exact filetrs should have accepted this file name", exactfileNameFilter.applyTo(log1, lethal));
    String notFileName = "FileFile.java";
    Filter noExactfileNameFilter = new ExactFilter(LogField.FILE, lethal, notFileName, false);
    assertFalse("Exact filetrs should have discarded this file name", noExactfileNameFilter.applyTo(log1, lethal));
    // Test the stack level
    Integer stackLvl = Integer.valueOf(12);
    Filter stackLvlFilter = new ExactFilter(LogField.STACKLEVEL, lethal, stackLvl, false);
    assertTrue("Exact filetrs should have accepted this stack level", stackLvlFilter.applyTo(log1, lethal));
    Integer noStackLvl = Integer.valueOf(10);
    Filter nostackLvlFilter = new ExactFilter(LogField.STACKLEVEL, lethal, noStackLvl, false);
    assertFalse("Exact filetrs should have discarded this stack level", nostackLvlFilter.applyTo(log1, lethal));
    // Test the timestamp
    Date date = df.parseIsoTimestamp("2013-08-04T15:10:10.512");
    Filter dateFilter = new ExactFilter(LogField.TIMESTAMP, lethal, date, false);
    assertTrue("Exact filetrs should have accepted this timestamp", dateFilter.applyTo(log1, lethal));
    Date noDate = df.parseIsoTimestamp("2013-08-04T16:10:10.888");
    Filter noDateFilter = new ExactFilter(LogField.TIMESTAMP, lethal, noDate, false);
    assertFalse("Exact filetrs should have discarded this timestamp", noDateFilter.applyTo(log1, lethal));
    // Test the LogEntryType
    Filter logTypeFiletr = new ExactFilter(LogField.ENTRYTYPE, lethal, LogTypeHelper.INFO, false);
    assertTrue("This log type filter should have accepted this type", logTypeFiletr.applyTo(log1, lethal));
    assertFalse("This log type filter should have discarded this type", logTypeFiletr.applyTo(log2, lethal));
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) RegExpFilter(com.cosylab.logging.engine.RegExpFilter) ExactFilter(com.cosylab.logging.engine.ExactFilter) MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) Filter(com.cosylab.logging.engine.Filter) Date(java.util.Date)

Aggregations

ExactFilter (com.cosylab.logging.engine.ExactFilter)9 Filter (com.cosylab.logging.engine.Filter)7 MinMaxFilter (com.cosylab.logging.engine.MinMaxFilter)5 RegExpFilter (com.cosylab.logging.engine.RegExpFilter)4 FiltersVector (com.cosylab.logging.engine.FiltersVector)2 Date (java.util.Date)2 AcsLogLevel (alma.acs.logging.AcsLogLevel)1 InvalidFilterConstraintException (com.cosylab.logging.engine.InvalidFilterConstraintException)1 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)1 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)1 File (java.io.File)1