Skip to content

Instantly share code, notes, and snippets.

@Amerousful
Created October 12, 2022 14:09
Show Gist options
  • Save Amerousful/faa2ff12b7316300984f5af75691f823 to your computer and use it in GitHub Desktop.
Save Amerousful/faa2ff12b7316300984f5af75691f823 to your computer and use it in GitHub Desktop.
Scala, Logback Multiply Level Filter
class MultipleLevelFilter extends AbstractMatcherFilter[ILoggingEvent] {
private var levels: Set[Level] = _
def setLevels(levels: String): Unit = {
this.levels = levels.split('|').map(Level.toLevel(_, Level.OFF)).toSet
}
def getLevels = levels
override def decide(event: ILoggingEvent) = {
if (levels.contains(event.getLevel)) onMatch
else onMismatch
}
override def start(): Unit = if (this.levels != null && levels.nonEmpty) super.start()
}
<filter class="logger.MultipleLevelFilter">
<levels>TRACE|DEBUG</levels>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment