Search in sources :

Example 6 with ExactFilter

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

the class TablePopupMenu method filters.

/**
	 * Filters out or shows only the longs under the mouse pointer
	 * by settng a new filter in the table.
	 * 
	 * @param out If <code>true</code> filters out logs
	 */
private void filters(boolean out) {
    // Clean the string from XML tags
    if (this.textToCopy.startsWith("<html>")) {
        this.textToCopy = this.textToCopy.substring(6, this.textToCopy.length());
        if (this.textToCopy.endsWith("</html>")) {
            this.textToCopy = this.textToCopy.substring(0, this.textToCopy.length() - 7);
        }
    }
    int colModelIndex = table.convertColumnIndexToModel(col);
    Comparable comparable = null;
    if (LogField.values()[colModelIndex - 1].getType() == String.class) {
        comparable = this.textToCopy;
    } else if (LogField.values()[colModelIndex - 1].getType() == Integer.class) {
        comparable = Integer.valueOf(this.textToCopy);
    } else if (LogField.values()[colModelIndex - 1].getType() == LogTypeHelper.class) {
        comparable = LogTypeHelper.fromLogTypeDescription(this.textToCopy);
    } else if (LogField.values()[colModelIndex - 1].getType() == Long.class) {
        // Timestamp
        try {
            comparable = Long.valueOf(IsoDateFormat.parseIsoTimestamp(this.textToCopy).getTime());
        } catch (Throwable t) {
            System.err.println("Error parsing date " + this.textToCopy + ": " + t.getMessage());
            t.printStackTrace(System.err);
            return;
        }
    }
    FiltersVector newFilterVector = new FiltersVector();
    try {
        ExactFilter newFilter = new ExactFilter(LogField.values()[colModelIndex - 1], false, comparable, out);
        newFilterVector.addFilter(newFilter, true);
    } catch (Throwable t) {
        System.err.println("Error creating filter " + t.getMessage());
        t.printStackTrace(System.err);
    }
    table.setFilters(newFilterVector, true);
    loggingClient.setTableFilterLbl();
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) FiltersVector(com.cosylab.logging.engine.FiltersVector)

Example 7 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter 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 8 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter 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 9 with ExactFilter

use of com.cosylab.logging.engine.ExactFilter 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)

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