LogFilter (Apache JMeter dist API)
Description: declaration: package: org.apache.jmeter.protocol.http.util.accesslog, class: LogFilter

Package org.apache.jmeter.protocol.http.util.accesslog

# Class LogFilter

java.lang.Object
org.apache.jmeter.protocol.http.util.accesslog.LogFilter

All Implemented Interfaces:
  `Serializable`, `Filter`

@AutoService(Filter.class) public class LogFilter extends Object implements Filter, Serializable
Description:
LogFilter is a basic implementation of Filter interface. This implementation will keep a record of the filtered strings to avoid repeating the process unnecessarily.

The current implementation supports replacing the file extension. The reason for supporting this is from first hand experience porting an existing website to Tomcat + JSP. Later on we may want to provide the ability to replace the whole filename. If the need materializes, we can add it later.

Example of how to use it is provided in the main method. An example is provided below.

     testf = new LogFilter();
     String[] incl = { "hello.html", "index.html", "/index.jsp" };
     String[] theFiles = {
         "/test/hello.jsp", "/test/one/hello.html", "hello.jsp", "hello.htm", "/test/open.jsp",
         "/test/open.html", "/index.jsp", "/index.jhtml", "newindex.jsp", "oldindex.jsp", "oldindex1.jsp",
         "oldindex2.jsp", "oldindex3.jsp", "oldindex4.jsp", "oldindex5.jsp", "oldindex6.jsp", "/test/index.htm"
     };
     testf.excludeFiles(incl);
     System.out.println(" ------------ exclude test -------------");
     for (String theFile : theFiles) {
      boolean fl = testf.isFiltered(theFile);
      String line = testf.filter(theFile);
      if (line != null) {
         System.out.println("the file: " + line);
      }
     }

As a general note. Both isFiltered and filter() have to be called. Calling either one will not produce the desired result. isFiltered(string) will tell you if a string should be filtered. The second step is to filter the string, which will return null if it is filtered and replace any part of the string that should be replaced.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected boolean`
  `CHANGEEXT`
  `protected String[]`
  `EXCFILE`
  `protected ArrayList<org.apache.oro.text.regex.Pattern>`
  `EXCPATTERNS`
  `protected String[]`
  `EXCPTRN`
  `protected boolean`
  `FILEFILTER`
  `protected String[]`
  `INCFILE`
  `protected ArrayList<org.apache.oro.text.regex.Pattern>`
  `INCPATTERNS`
  `protected String[]`
  `INCPTRN`
  `protected String`
  `NEWEXT`
  `protected String`
  `NEWFILE`
  `protected String`
  `OLDEXT`
  `protected boolean`
  `PTRNFILTER`
  `protected boolean`
  `USEFILE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LogFilter()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `org.apache.oro.text.regex.Pattern`
  `createPattern(String pattern)`
  create a new pattern object from the string.
  `boolean`
  `excFile(String text)`
  Method implements the logic for filtering file name exclusion.
  `void`
  `excludeFiles(String[] filenames)`
  Give the filter a list of files to exclude
  `void`
  `excludePattern(String[] regexp)`
  Give the filter a set of regular expressions to filter with for exclusion.
  `protected boolean`
  `excPattern(String text)`
  The method assumes by default the text is not excluded.
  `String`
  `filter(String text)`
  The current implementation checks the boolean if the text should be used or not.
  `protected boolean`
  `filterFile(String file)`
  Filter the file.
  `protected boolean`
  `filterPattern(String text)`
  The current implementation assumes the user has checked the regular expressions so that they don't cancel each other.
  `boolean`
  `incFile(String text)`
  Method implements the logic for filtering file name inclusion.
  `void`
  `includeFiles(String[] filenames)`
  Give the filter a list of files to include
  `void`
  `includePattern(String[] regexp)`
  Give the filter a set of regular expressions to filter with for inclusion.
  `protected boolean`
  `incPattern(String text)`
  By default, the method assumes the entry is not included, unless it matches.
  `boolean`
  `isFiltered(String path, org.apache.jmeter.testelement.TestElement el)`
  In the case of log filtering the important thing is whether the log entry should be used.
  `boolean`
  `replaceExtension(String text)`
  Method uses indexOf to replace the old extension with the new extension.
  `void`
  `reset()`
  Tell the filter when the parsing has reached the end of the log file and is about to begin again.
  `void`
  `setReplaceExtension(String oldext, String newext)`
  The method will replace the file extension with the new one.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### CHANGEEXT

    protected boolean CHANGEEXT

  - ### OLDEXT

    protected String OLDEXT

  - ### NEWEXT

    protected String NEWEXT

  - ### INCFILE

    protected String[] INCFILE

  - ### EXCFILE

    protected String[] EXCFILE

  - ### FILEFILTER

    protected boolean FILEFILTER

  - ### USEFILE

    protected boolean USEFILE

  - ### INCPTRN

    protected String[] INCPTRN

  - ### EXCPTRN

    protected String[] EXCPTRN

  - ### PTRNFILTER

    protected boolean PTRNFILTER

  - ### EXCPATTERNS

    protected ArrayList<org.apache.oro.text.regex.Pattern> EXCPATTERNS

  - ### INCPATTERNS

    protected ArrayList<org.apache.oro.text.regex.Pattern> INCPATTERNS

  - ### NEWFILE

    protected String NEWFILE

- ## Constructor Details

  - ### LogFilter

    public LogFilter()

- ## Method Details

  - ### setReplaceExtension

    public void setReplaceExtension(String oldext, String newext)
    The method will replace the file extension with the new one. You can either provide the extension without the period ".", or with. The method will check for period and add it if it isn't present.
    Specified by:
      `setReplaceExtension` in interface `Filter`
    Parameters:
      `oldext` - old extension
      `newext` - new extension
    See Also:
      - `Filter.setReplaceExtension(java.lang.String, java.lang.String)`

  - ### includeFiles

    public void includeFiles(String[] filenames)
    Give the filter a list of files to include
    Specified by:
      `includeFiles` in interface `Filter`
    Parameters:
      `filenames` - list of files to include
    See Also:
      - `Filter.includeFiles(java.lang.String[])`

  - ### excludeFiles

    public void excludeFiles(String[] filenames)
    Give the filter a list of files to exclude
    Specified by:
      `excludeFiles` in interface `Filter`
    Parameters:
      `filenames` - list of files to exclude
    See Also:
      - `Filter.excludeFiles(java.lang.String[])`

  - ### includePattern

    public void includePattern(String[] regexp)
    Give the filter a set of regular expressions to filter with for inclusion. This method hasn't been fully implemented and test yet. The implementation is not complete.
    Specified by:
      `includePattern` in interface `Filter`
    Parameters:
      `regexp` - list of regular expressions
    See Also:
      - `Filter.includePattern(String[])`

  - ### excludePattern

    public void excludePattern(String[] regexp)
    Give the filter a set of regular expressions to filter with for exclusion. This method hasn't been fully implemented and test yet. The implementation is not complete.
    Specified by:
      `excludePattern` in interface `Filter`
    Parameters:
      `regexp` - list of regular expressions
    See Also:
      - `Filter.excludePattern(String[])`

  - ### isFiltered

    public boolean isFiltered(String path, org.apache.jmeter.testelement.TestElement el)
    In the case of log filtering the important thing is whether the log entry should be used. Therefore, the method will only return true if the entry should be used. Since the interface defines both inclusion and exclusion, that means by default inclusion filtering assumes all entries are excluded unless it matches. In the case of exclusion filtering, it assumes all entries are included unless it matches, which means it should be excluded.
    Specified by:
      `isFiltered` in interface `Filter`
    Parameters:
      `path` - path to be tested
      `el` - `TestElement` in which the line would be added
    Returns:
      `true` if entry should be excluded
    See Also:
      - `Filter.isFiltered(String, TestElement)`

  - ### filterFile

    protected boolean filterFile(String file)
    Filter the file. The implementation performs the exclusion first before the inclusion. This means if a file name is in both string arrays, the exclusion will take priority. Depending on how users expect this to work, we may want to change the priority so that inclusion is performed first and exclusion second. Another possible alternative is to perform both inclusion and exclusion. Doing so would make the most sense if the method throws an exception and tells the user the same filename is in both the include and exclude array.
    Parameters:
      `file` - the file to filter
    Returns:
      boolean

  - ### incFile

    public boolean incFile(String text)
    Method implements the logic for filtering file name inclusion. The method iterates through the array and uses indexOf. Once it finds a match, it won't bother with the rest of the filenames in the array.
    Parameters:
      `text` - name of the file to tested (must not be `null`)
    Returns:
      boolean include

  - ### excFile

    public boolean excFile(String text)
    Method implements the logic for filtering file name exclusion. The method iterates through the array and uses indexOf. Once it finds a match, it won't bother with the rest of the filenames in the array.
    Parameters:
      `text` - name of the file to be tested (must not be null)
    Returns:
      boolean exclude

  - ### filterPattern

    protected boolean filterPattern(String text)
    The current implementation assumes the user has checked the regular expressions so that they don't cancel each other. The basic assumption is the method will return true if the text should be filtered. If not, it will return false, which means it should not be filtered.
    Parameters:
      `text` - text to be checked
    Returns:
      boolean

  - ### incPattern

    protected boolean incPattern(String text)
    By default, the method assumes the entry is not included, unless it matches. In that case, it will return true.
    Parameters:
      `text` - text to be checked
    Returns:
      `true` if text is included

  - ### excPattern

    protected boolean excPattern(String text)
    The method assumes by default the text is not excluded. If the text matches the pattern, it will then return true.
    Parameters:
      `text` - text to be checked
    Returns:
      `true` if text is excluded

  - ### replaceExtension

    public boolean replaceExtension(String text)
    Method uses indexOf to replace the old extension with the new extension. It might be good to use regular expression, but for now this is a simple method. The method isn't designed to replace multiple instances of the text, since that isn't how file extensions work. If the string contains more than one instance of the old extension, only the first instance will be replaced.
    Parameters:
      `text` - name of the file in which the extension should be replaced (must not be null)
    Returns:
      `true` if the extension could be replaced, `false` otherwise

  - ### filter

    public String filter(String text)
    The current implementation checks the boolean if the text should be used or not. isFilter( string) has to be called first.
    Specified by:
      `filter` in interface `Filter`
    Parameters:
      `text` - log line to be filtered
    Returns:
      String
    See Also:
      - `Filter.filter(java.lang.String)`

  - ### createPattern

    public org.apache.oro.text.regex.Pattern createPattern(String pattern)
    create a new pattern object from the string.
    Parameters:
      `pattern` - string representation of the perl5 compatible regex pattern
    Returns:
      compiled Pattern, or `null` if no pattern could be compiled

  - ### reset

    public void reset()
    Tell the filter when the parsing has reached the end of the log file and is about to begin again. Gives the filter a chance to adjust it's values, if needed.
    Specified by:
      `reset` in interface `Filter`