Class DefaultLogEntryFilter

java.lang.Object
com.dua3.utility.logging.DefaultLogEntryFilter
All Implemented Interfaces:
LogEntryFilter, Predicate<LogEntry>

public class DefaultLogEntryFilter extends Object implements LogEntryFilter
The DefaultLogEntryFilter class is an implementation of the LogEntryFilter interface that filters log entries based on their log level and a user-defined filter.

DefaultLogEntryFilter provides methods to set and retrieve the log level and filter, as well as a test method to determine if a LogEntry should be included or excluded.

  • Constructor Details

    • DefaultLogEntryFilter

      public DefaultLogEntryFilter()
      Constructs a new DefaultLogEntryFilter with LogLevel.TRACE as the default log level and a filter that lets all log entries pass.
    • DefaultLogEntryFilter

      public DefaultLogEntryFilter(LogLevel level, BiPredicate<String,LogLevel> filter)
      Constructs a new DefaultLogEntryFilter with the specified log level and filter.
      Parameters:
      level - the log level to set
      filter - the filter to set
  • Method Details

    • setLevel

      public void setLevel(LogLevel level)
      Sets the log level of the DefaultLogEntryFilter.
      Parameters:
      level - the log level to set
    • getLevel

      public LogLevel getLevel()
      Retrieves the log level of the DefaultLogEntryFilter.
      Returns:
      The log level of the DefaultLogEntryFilter.
    • setFilter

      public void setFilter(BiPredicate<String,LogLevel> filter)
      Sets the filter of the DefaultLogEntryFilter.
      Parameters:
      filter - A BiPredicate that takes a logger name and a log level as input and returns a boolean indicating whether the log entry should be filtered or not. The first argument is the logger name, and the second argument is the log level. Returns true if the log entry should be included, false otherwise.
    • getFilter

      public BiPredicate<String,LogLevel> getFilter()
      Retrieves the filter used to determine if a log entry should be included or excluded.
      Returns:
      The filter used to determine if a log entry should be included or excluded.
      See Also:
    • test

      public boolean test(LogEntry logEntry)
      Description copied from interface: LogEntryFilter
      Test if a LogEntry should be processed.
      Specified by:
      test in interface LogEntryFilter
      Specified by:
      test in interface Predicate<LogEntry>
      Parameters:
      logEntry - the input argument
      Returns:
      true, if the logEntry should be processed, false if it should be filtered out
    • copy

      public DefaultLogEntryFilter copy()
      Creates a copy of the DefaultLogEntryFilter with the same log level and filter.
      Returns:
      A new {code DefaultLogEntryFilter} instance with the same log level and filter.
    • withLevel

      public DefaultLogEntryFilter withLevel(LogLevel newLevel)
      Returns a new DefaultLogEntryFilter with the same filter and the specified log level.
      Parameters:
      newLevel - the log level to set
      Returns:
      a new {code DefaultLogEntryFilter} instance with the specified log level
    • withFilter

      public DefaultLogEntryFilter withFilter(BiPredicate<String,LogLevel> newFilter)
      Returns a new {code DefaultLogEntryFilter} with the same log level and the specified filter.
      Parameters:
      newFilter - the new filter to set
      Returns:
      a new instance of {code DefaultLogEntryFilter} with the specified filter