Search in sources :

Example 11 with Filter

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

the class EngineFilteringTest method testAddFiltersVector.

/**
	 * Test adding a FiltersVector
	 */
public void testAddFiltersVector() 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);
    // Create and add another filter
    Filter f2 = new ExactFilter(LogField.ENTRYTYPE, false, LogTypeHelper.DEBUG, false);
    assertNotNull(f2);
    // Setup the filters vector
    FiltersVector filters = new FiltersVector();
    assertNotNull(filters);
    filters.addFilter(f, true);
    filters.addFilter(f2, true);
    // Set the filters
    engine.setFilters(filters, false);
    assertNotNull(engine.getFilters());
    assertEquals(filters.size(), engine.getFilters().size());
    // Append the filters
    engine.setFilters(filters, true);
    assertNotNull(engine.getFilters());
    assertEquals(filters.size() * 2, engine.getFilters().size());
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) ExactFilter(com.cosylab.logging.engine.ExactFilter) Filter(com.cosylab.logging.engine.Filter) FiltersVector(com.cosylab.logging.engine.FiltersVector)

Example 12 with Filter

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

the class FiltersVectorTest method testApplyFilters.

/**
	 * Test {@link FiltersVector#applyFilters(com.cosylab.logging.engine.log.ILogEntry)}
	 */
public void testApplyFilters() throws Exception {
    // All logs are accepted if the vector is empty
    assertTrue("All logs accepted if no filters", filters.applyFilters(log1));
    assertTrue("All logs accepted if no filters", filters.applyFilters(log2));
    assertTrue("All logs accepted if no filters", filters.applyFilters(log3));
    // All logs are accepted if the vector has filters but no one is active
    Filter exactLogMessageFilter = new ExactFilter(LogField.LOGMESSAGE, lethal, "A message for a log", false);
    filters.addFilter(exactLogMessageFilter, false);
    Filter stackLvlFilter = new ExactFilter(LogField.STACKLEVEL, lethal, Integer.valueOf(12), false);
    filters.addFilter(stackLvlFilter, false);
    assertTrue("All logs accepted if no filters", filters.applyFilters(log1));
    assertTrue("All logs accepted if no filters", filters.applyFilters(log2));
    assertTrue("All logs accepted if no filters", filters.applyFilters(log3));
    filters.clear();
    assertFalse("The empty vector has no active filters", filters.hasActiveFilters());
    // Only log1 should pass
    filters.addFilter(exactLogMessageFilter, true);
    assertTrue("The vector should contain one active filter", filters.hasActiveFilters());
    assertTrue("log1 should be accepted", filters.applyFilters(log1));
    assertFalse("log2 logs NOT accepted", filters.applyFilters(log2));
    assertFalse("log3 logs NOT accepted", filters.applyFilters(log3));
    filters.clear();
    assertFalse("The empty vector has no active filters", filters.hasActiveFilters());
    // Test with 2 filters
    Filter exactLogMessageFilter2 = new ExactFilter(LogField.LOGMESSAGE, lethal, "A message for log2", false);
    Filter lineFilter = new ExactFilter(LogField.LINE, lethal, Integer.valueOf(95), false);
    filters.addFilter(exactLogMessageFilter2, true);
    filters.addFilter(lineFilter, true);
    assertFalse("log1 should NOT be accepted", filters.applyFilters(log1));
    assertTrue("log2 logs accepted", filters.applyFilters(log2));
    assertFalse("log3 logs NOT accepted", filters.applyFilters(log3));
}
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 13 with Filter

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

the class FiltersVectorTest method testLoadSave.

/**
	 * Test the saving and loading of the filters.
	 * <P>The test is done by:
	 * <UL>
	 * 	<LI>Setting up some filters
	 *  <LI>Saving the filters in a temporary file
	 *  <LI>Clearing the vector of filters
	 *  <LI>Loading the filters
	 *  <LI>Checking if the loaded filters are the same filters that had been saved
	 * </UL>
	 * The checking of filters is done also printing {@link FiltersVector#getFilterString()} in the stdout:
	 * tat will check for correctness. Besides that, each filter will be checked 
	 * @throws Exception
	 */
public void testLoadSave() throws Exception {
    // Define few interesting filters
    Filter exactLogMessageFilter = new ExactFilter(LogField.LOGMESSAGE, lethal, "One message", false);
    Filter regExpLogMessageFilter = new RegExpFilter(LogField.SOURCEOBJECT, lethal, "RegExpr.*", false);
    Date maxDate = df.parseIsoTimestamp("2013-08-07T15:10:10.512");
    Date minDate = df.parseIsoTimestamp("2013-08-02T15:10:10.512");
    Filter minMaxDateFilter = new MinMaxFilter(LogField.TIMESTAMP, lethal, minDate, maxDate, false);
    Integer maxType = LogTypeHelper.fromAcsCoreLevel(AcsLogLevelDefinition.NOTICE).ordinal();
    Integer minType = LogTypeHelper.fromAcsCoreLevel(AcsLogLevelDefinition.DEBUG).ordinal();
    Filter minMaxTypeFilter = new MinMaxFilter(LogField.ENTRYTYPE, lethal, minType, maxType, false);
    Date excatDate = df.parseIsoTimestamp("2011-09-02T10:21:18.333");
    Filter exactDateFilter = new ExactFilter(LogField.TIMESTAMP, lethal, excatDate, false);
    Filter exactStackLevelFilter = new ExactFilter(LogField.STACKLEVEL, lethal, Integer.valueOf(13), false);
    Filter minMaxLineFilter = new MinMaxFilter(LogField.LINE, lethal, Integer.valueOf(7), Integer.valueOf(320), false);
    Filter exactTypeFilter = new ExactFilter(LogField.ENTRYTYPE, lethal, LogTypeHelper.EMERGENCY, false);
    filters.addFilter(exactLogMessageFilter, true);
    filters.addFilter(regExpLogMessageFilter, false);
    filters.addFilter(minMaxDateFilter, true);
    filters.addFilter(minMaxTypeFilter, false);
    filters.addFilter(exactDateFilter, true);
    filters.addFilter(exactStackLevelFilter, true);
    filters.addFilter(minMaxLineFilter, false);
    filters.addFilter(exactTypeFilter, false);
    assertEquals("We added 8 filters!", 8, filters.size());
    System.out.println("Filters to save: " + filters.getFilterString());
    // Save filters
    String dir = System.getProperty("user.dir");
    String fileName = dir + "/TestSaveLoad.xml";
    File outF = new File(fileName);
    filters.saveFilters(outF);
    // Clear the vector of filters
    filters.clear();
    // Load filters
    filters.loadFilters(outF, true, fileName);
    System.out.println("Loaded filters: " + filters.getFilterString());
    // Check each filter
    assertEquals("Loaded filters differ from saved filters", 8, filters.size());
    for (int t = 0; t < filters.size(); t++) {
        Filter flt = filters.get(t);
        System.out.println(flt.toString());
    }
    // Check if the activation state has been saved correctly
    assertTrue("Invalid \"ENABLED\" state", filters.isActive(0));
    assertFalse("Invalid \"ENABLED\" state", filters.isActive(1));
    assertTrue("Invalid \"ENABLED\" state", filters.isActive(2));
    assertFalse("Invalid \"ENABLED\" state", filters.isActive(3));
    assertTrue("Invalid \"ENABLED\" state", filters.isActive(4));
    assertTrue("Invalid \"ENABLED\" state", filters.isActive(5));
    assertFalse("Invalid \"ENABLED\" state", filters.isActive(6));
    assertFalse("Invalid \"ENABLED\" state", filters.isActive(7));
    // Remove the file
    outF.delete();
}
Also used : MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) 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) RegExpFilter(com.cosylab.logging.engine.RegExpFilter) File(java.io.File) Date(java.util.Date)

Example 14 with Filter

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

the class LogTableRowSorter method setFilters.

/* (non-Javadoc)
	 * @see com.cosylab.logging.engine.Filterable#setFilters(com.cosylab.logging.engine.FiltersVector, boolean)
	 */
@Override
public void setFilters(FiltersVector newFilters, boolean append) {
    if (append) {
        for (int t = 0; t < newFilters.size(); t++) {
            Filter f = newFilters.get(t);
            filters.addFilter(f, newFilters.isActive(t));
        }
    } else {
        if (newFilters == null) {
            filters.clear();
        } else {
            filters.setFilters(newFilters);
        }
    }
    // apply the filters
    applyChanges();
}
Also used : Filter(com.cosylab.logging.engine.Filter)

Aggregations

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