Created
October 12, 2022 14:09
-
-
Save Amerousful/faa2ff12b7316300984f5af75691f823 to your computer and use it in GitHub Desktop.
Scala, Logback Multiply Level Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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