Skip to content

Commit

Permalink
Added || support to filters expanding #273
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Feb 23, 2022
1 parent 1f5a9ee commit 9ef2805
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scribe.filter

import scribe.LogRecord

case class MultiFilter(filters: List[Filter]) extends Filter {
case class AndFilters(filters: List[Filter]) extends Filter {
override def matches[M](record: LogRecord[M]): Boolean = filters.forall(_.matches(record))

override def &&(that: Filter): Filter = copy(filters ::: List(that))
Expand Down
3 changes: 2 additions & 1 deletion core/shared/src/main/scala/scribe/filter/Filter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import scribe.LogRecord
trait Filter {
def matches[M](record: LogRecord[M]): Boolean

def &&(that: Filter): Filter = MultiFilter(List(this, that))
def &&(that: Filter): Filter = AndFilters(List(this, that))
def ||(that: Filter): Filter = OrFilters(List(this, that))
}
9 changes: 9 additions & 0 deletions core/shared/src/main/scala/scribe/filter/OrFilters.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scribe.filter

import scribe.LogRecord

case class OrFilters(filters: List[Filter]) extends Filter {
override def matches[M](record: LogRecord[M]): Boolean = filters.exists(_.matches(record))

override def ||(that: Filter): Filter = copy(filters ::: List(that))
}

0 comments on commit 9ef2805

Please sign in to comment.