/
LoggingAction.scala
53 lines (44 loc) · 2.18 KB
/
LoggingAction.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
package info.kwarc.mmt.api.frontend.actions
import info.kwarc.mmt.api.frontend._
/** shared base class for actions related to logging */
sealed abstract class LoggingAction extends Action {}
case object ListReportGroups extends LoggingAction with ResponsiveAction {
def apply() = {
respond("the following log groups are active: ")
logGroup {
report.active.foreach(respond(_))
}
respond("use 'log+ <group>' to add a log group. ")
respond("use 'log- <group>' to remove a log group. ")
}
def toParseString: String = "show log groups"
}
object ListReportGroupsCompanion extends ObjectActionCompanion(ListReportGroups, "list active log groups", "show log groups")
case class AddReportHandler(h: ReportHandler) extends LoggingAction {
def apply() =controller.report.addHandler(h)
def toParseString = s"log $h"
}
object AddReportHandlerCompanion extends ActionCompanion("add a log handler", "log") {
import Action._
def parserActual(implicit state: ActionState) = logfilets | logfile | loghtml | logconsole
private def logfile(implicit state: ActionState) = "file" ~> file ^^ { f => AddReportHandler(new TextFileHandler(f, false)) }
private def logfilets(implicit state: ActionState) = "filets" ~> file ^^ { f => AddReportHandler(new TextFileHandler(f, true)) }
private def logconsole(implicit state: ActionState) = "console" ^^ { case _ => AddReportHandler(ConsoleHandler) }
private def loghtml(implicit state: ActionState) = "html" ~> file ^^ { f => AddReportHandler(new HtmlFileHandler(f)) }
}
case class LoggingOn(group: String) extends LoggingAction {
def apply() =report.groups += group
def toParseString = s"log+ $group"
}
object LoggingOnCompanion extends ActionCompanion("switch on logging for a certain group", "log+") {
import Action._
def parserActual(implicit state: ActionState) = reststr ^^ { s => LoggingOn(s) }
}
case class LoggingOff(group: String) extends LoggingAction {
def apply() =report.groups -= group
def toParseString = s"log- $group"
}
object LoggingOffCompanion extends ActionCompanion("switch off logging for a certain group", "log-") {
import Action._
def parserActual(implicit state: ActionState) = str ^^ { s => LoggingOff(s) }
}