Search in sources :

Example 6 with MinMaxFilter

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

the class FileHelper method setupFilters.

/**
	 * Create the filters for loading logs;:
	 * <UL>
	 * 	<LI>time range
	 * 	<LI>min and max log levels
	 * </UL>
	 * @return
	 */
private FiltersVector setupFilters() throws ZoomException {
    FiltersVector filters = new FiltersVector();
    Filter dateFilter = null;
    Filter levelFilter = null;
    try {
        dateFilter = new MinMaxFilter(LogField.TIMESTAMP, false, startTime, endTime, false);
        levelFilter = new MinMaxFilter(LogField.ENTRYTYPE, false, minLogLevel, maxLogLevel, false);
    } catch (InvalidFilterConstraintException e) {
        throw new ZoomException("Error setting the filters", e);
    }
    filters.addFilter(dateFilter, true);
    filters.addFilter(levelFilter, true);
    return filters;
}
Also used : MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) MinMaxFilter(com.cosylab.logging.engine.MinMaxFilter) Filter(com.cosylab.logging.engine.Filter) FiltersVector(com.cosylab.logging.engine.FiltersVector) InvalidFilterConstraintException(com.cosylab.logging.engine.InvalidFilterConstraintException)

Example 7 with MinMaxFilter

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

the class FilterDatePanel method getFilter.

/**
 * Insert the method's description here.
 * Creation date: (2/7/02 11:59:47 AM)
 * @return com.cosylab.logging.engine.Filter
 * @exception com.cosylab.logging.engine.InvalidFilterConstraintException The exception description.
 */
public Filter getFilter() throws FilterParameterException {
    Date min = null;
    Date max = null;
    if (minimumCheck.isSelected()) {
        min = minimum.getDate().getTime();
    //		System.out.println(min.toString());
    }
    if (maximumCheck.isSelected()) {
        max = maximum.getDate().getTime();
    //		System.out.println(max.toString());
    }
    if ((min == null) && (max == null)) {
        throw new FilterParameterException("Select at least one constraint");
    }
    if ((min != null) && (max != null)) {
        if (min.compareTo(max) > -1)
            throw new FilterParameterException("From must be less than To");
    }
    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) Date(java.util.Date) InvalidFilterConstraintException(com.cosylab.logging.engine.InvalidFilterConstraintException)

Example 8 with MinMaxFilter

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

MinMaxFilter (com.cosylab.logging.engine.MinMaxFilter)8 ExactFilter (com.cosylab.logging.engine.ExactFilter)6 Filter (com.cosylab.logging.engine.Filter)6 RegExpFilter (com.cosylab.logging.engine.RegExpFilter)5 Date (java.util.Date)5 InvalidFilterConstraintException (com.cosylab.logging.engine.InvalidFilterConstraintException)4 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)4 FiltersVector (com.cosylab.logging.engine.FiltersVector)1 File (java.io.File)1