-
Notifications
You must be signed in to change notification settings - Fork 25
/
LogThreshold.scala
46 lines (40 loc) · 1.31 KB
/
LogThreshold.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.log4s
package log4sjs
import scala.math.Ordered._
import scala.scalajs.js
import js.annotation._
/** A threshold that can be applied to log configuration or filtering.
*
* This includes all log levels, plus additional "all" and "off" levels.
*/
sealed trait LogThreshold extends Any {
def permits(ll: LogLevel): Boolean = this <= LevelThreshold(ll)
}
object LogThreshold {
case object AllThreshold extends LogThreshold
case object OffThreshold extends LogThreshold
implicit val order: Ordering[LogThreshold] = Ordering.by {
case OffThreshold => Int.MaxValue
case LevelThreshold(Error) => 40000
case LevelThreshold(Warn) => 30000
case LevelThreshold(Info) => 20000
case LevelThreshold(Debug) => 10000
case LevelThreshold(Trace) => 5000
case AllThreshold => Int.MinValue
}
def forName(name: String): LogThreshold = {
name.toLowerCase match {
case "off" => OffThreshold
case "all" => AllThreshold
case other => LevelThreshold(LogLevel.forName(other))
}
}
}
object LevelThreshold {
def apply(ll: LogLevel) = new LevelThreshold(ll)
def unapply(lt: LogThreshold) = lt match {
case lt: LevelThreshold => Some(lt.inner)
case _ => None
}
}
class LevelThreshold(val inner: LogLevel) extends AnyVal with LogThreshold