Create a custom filter

A Filter provides optional, secondary control over what is logged, beyond the control provided by the level.

The mechanism for creating a customer filter is the Filter interface support provided by the IBM Developer Kit, Java Technology Edition. If you are not familiar with filters as implemented by the Developer's Kit, one can get more information from various texts, or by reading the Javadoc for java.util.logging.

The following is an example of a custom filter

import java.util.Vector;
import java.util.logging.Filter;
import java.util.logging.LogRecord;

/**
 * MyCustomFilter rejects any LogRecords whose Level is not contained in the
 * configured list of Levels. 
 */
public class MyCustomFilter implements Filter {

  private Vector acceptableLevels;

  public MyCustomFilter(Vector acceptableLevels) {
    super();
    this.acceptableLevels = acceptableLevels;
  }

  /* (non-Javadoc)
   * @see java.util.logging.Filter#isLoggable(java.util.logging.LogRecord)
   */
  public boolean isLoggable(LogRecord record) {     
    return (acceptableLevels.contains(record.getLevel()));
  }

}

 



 

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.