-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathLog.scala
58 lines (50 loc) · 1.5 KB
/
Log.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
47
48
49
50
51
52
53
54
55
56
57
58
package io.kaitai.struct
sealed trait Logger {
def info(msgGen: () => String)
def warn(msgGen: () => String)
}
case object NullLogger extends Logger {
override def info(msgGen: () => String): Unit = {}
override def warn(msgGen: () => String): Unit = {}
}
case object ConsoleLogger extends Logger {
override def info(msgGen: () => String): Unit = {
val msg: String = msgGen()
Console.println(msg)
}
override def warn(msgGen: () => String): Unit = info(msgGen)
}
object Log {
val VALID_SUBSYS = Seq(
"file",
"value",
"parent",
"type_resolve",
"type_valid",
"seq_sizes",
"import",
"enum_resolve"
)
var fileOps: Logger = NullLogger
var typeProcValue: Logger = NullLogger
var typeProcParent: Logger = NullLogger
var typeResolve: Logger = NullLogger
var typeValid: Logger = NullLogger
var seqSizes: Logger = NullLogger
var importOps: Logger = NullLogger
var enumResolve: Logger = NullLogger
def initFromVerboseFlag(subsystems: Seq[String]): Unit = {
fileOps = NullLogger
typeProcParent = NullLogger
subsystems.foreach {
case "file" => fileOps = ConsoleLogger
case "value" => typeProcValue = ConsoleLogger
case "parent" => typeProcParent = ConsoleLogger
case "type_resolve" => typeResolve = ConsoleLogger
case "type_valid" => typeValid = ConsoleLogger
case "seq_sizes" => seqSizes = ConsoleLogger
case "import" => importOps = ConsoleLogger
case "enum_resolve" => enumResolve = ConsoleLogger
}
}
}