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 looger name and message filters that let all log entries pass.
    • DefaultLogEntryFilter

      public DefaultLogEntryFilter(LogLevel level, BiPredicate<String,LogLevel> filterLoggerName, BiPredicate<String,LogLevel> filterText)
      Constructs a new DefaultLogEntryFilter with the specified log level and filter.
      Parameters:
      level - the log level to set
      filterLoggerName - the filter to set for the logger name
      filterText - the filter to set for the message content
  • 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.
    • setFilterLoggerName

      public void setFilterLoggerName(BiPredicate<String,LogLevel> filterLoggerName)
      Sets the logger name filterLoggerName of the DefaultLogEntryFilter.
      Parameters:
      filterLoggerName - 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.
    • getFilterLoggerName

      public BiPredicate<String,LogLevel> getFilterLoggerName()
      Retrieves the filter used to determine if a log entry should be included or excluded based on the logger name.
      Returns:
      The filter used to determine if a log entry should be included or excluded based on the logger name.
      See Also:
    • setFilterText

      public void setFilterText(BiPredicate<String,LogLevel> filterText)
      Sets the message filterText of the DefaultLogEntryFilter.
      Parameters:
      filterText - A BiPredicate that takes a log message 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 message text, and the second argument is the log level. Returns true if the log entry should be included, false otherwise.
    • getFilterText

      public BiPredicate<String,LogLevel> getFilterText()
      Retrieves the filter used to determine if a log entry should be included or excluded based on the logger name.
      Returns:
      The filter used to determine if a log entry should be included or excluded based on the logger name.
      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
    • withFilterLoggerName

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

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