Search in sources :

Example 1 with RegExpFilter

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

the class FilterTest method testRegexpFilterType.

/**
	 * Check if the filter works for exact value of log type.
	 */
public void testRegexpFilterType() throws Exception {
    // Test the LogMessgae against regexp
    String regExpToTest = "..message.for.*";
    Filter regExpLogMessageFilter = new RegExpFilter(LogField.LOGMESSAGE, lethal, regExpToTest, false);
    assertTrue("Regexp filter should have accepted this log msg", regExpLogMessageFilter.applyTo(log1, lethal));
    String noRegExpToTest = "Another message";
    Filter noRegExpLogMessageFilter = new RegExpFilter(LogField.LOGMESSAGE, lethal, noRegExpToTest, false);
    assertFalse("Regexp filter should have discarded this log msg", noRegExpLogMessageFilter.applyTo(log1, lethal));
    // Test source object
    String regSrcExpToTest = "source.*";
    Filter regExpSrcFilter = new RegExpFilter(LogField.SOURCEOBJECT, lethal, regSrcExpToTest, false);
    assertTrue("Regexp filter should have accepted this source object", regExpSrcFilter.applyTo(log1, lethal));
    String noRegSrcExpToTest = "Another message";
    Filter noRegExpSrcFilter = new RegExpFilter(LogField.SOURCEOBJECT, lethal, noRegSrcExpToTest, false);
    assertFalse("Regexp filter should have discarded this source object", noRegExpSrcFilter.applyTo(log1, lethal));
}
Also used : 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)

Example 2 with RegExpFilter

use of com.cosylab.logging.engine.RegExpFilter 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)2 Filter (com.cosylab.logging.engine.Filter)2 MinMaxFilter (com.cosylab.logging.engine.MinMaxFilter)2 RegExpFilter (com.cosylab.logging.engine.RegExpFilter)2 File (java.io.File)1 Date (java.util.Date)1