SOURCECODE

How to... define a LogEntryFilter


Description:
A LogEntryFilter is used either to enable logging of certain LogEntries only or to display / process certain LogEntries of a Log (which is a representation of the "log file")
To "filter" the LogEntries, set the filter to the LogOutputStream or LogInputStream that is being used. It will check wether the handed over LogEntry suits the condition described in the method accept(LogEntry le) of LogEntryFilter.
The easyest way to decide on the acception is by cheking wether a LogEntry is an instance of something or not, but anything that tells LogEntries from will do.
In this expample we define a LogEntryFilter that will only accept instances of OpenLogEntry, which is another example, defining a LogEntry for the opening of the VideoMachine Counter.

ToDo's:
  1. Create a new class implementing LogEntryFilter
  2. Implement accept(LogEntry le) to return true if a le is an instance of OpenLogEntry
  3. Use the LogEntryFilter with the designated LogInputStream or LogOutputStream


Uses:
LogEntryFilter  



SourceCode

import log.*;

 1
//An implementation of the Interface LogEntryFilter
public class OpenLogEntryFilter implements LogEntryFilter {
     2
    //This method contains the filter condition
    public boolean accept (LogEntry le) {
        //that will return true if le is an instance of OpenLogEntry
        return (le instanceof OpenLogEntry);
    }
}