aboutsummaryrefslogtreecommitdiff
path: root/stage1/logger.scala
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-02-06 13:03:36 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2016-03-04 15:06:30 -0500
commit974942db43ff2d1fa7ba71ad60f9bb9eae2d8631 (patch)
treed7235df9d4d6a67753dc2a20ab6bfcb7a24dc74c /stage1/logger.scala
downloadcbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.tar.gz
cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.tar.bz2
cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.zip
CBT Version 1.0-BETA
Diffstat (limited to 'stage1/logger.scala')
-rw-r--r--stage1/logger.scala41
1 files changed, 41 insertions, 0 deletions
diff --git a/stage1/logger.scala b/stage1/logger.scala
new file mode 100644
index 0000000..16bd940
--- /dev/null
+++ b/stage1/logger.scala
@@ -0,0 +1,41 @@
+package cbt
+import java.time._
+// We can replace this with something more sophisticated eventually
+case class Logger(enabledLoggers: Set[String]){
+ val start = LocalTime.now()
+ //System.err.println("Created Logger("+enabledLoggers+")")
+ def this(enabledLoggers: Option[String]) = this( enabledLoggers.toVector.flatMap( _.split(",") ).toSet )
+ def log(name: String, msg: => String) = {
+ val timeTaken = (Duration.between(start, LocalTime.now()).toMillis.toDouble / 1000).toString
+ System.err.println( s"[${" "*(6-timeTaken.size)}$timeTaken]["+name+"] " + msg )
+ }
+
+ def showInvocation(method: String, args: Any) = method + "( " + args + " )"
+
+ final def stage1(msg: => String) = logGuarded(names.stage1, msg)
+ final def stage2(msg: => String) = logGuarded(names.stage2, msg)
+ final def loop(msg: => String) = logGuarded(names.loop, msg)
+ final def task(msg: => String) = logGuarded(names.task, msg)
+ final def composition(msg: => String) = logGuarded(names.composition, msg)
+ final def resolver(msg: => String) = logGuarded(names.resolver, msg)
+ final def lib(msg: => String) = logGuarded(names.lib, msg)
+
+ private object names{
+ val stage1 = "stage1"
+ val stage2 = "stage2"
+ val loop = "loop"
+ val task = "task"
+ val resolver = "resolver"
+ val composition = "composition"
+ val lib = "lib"
+ }
+
+ private def logGuarded(name: String, msg: => String) = {
+ if(
+ (enabledLoggers contains name)
+ || (enabledLoggers contains "all")
+ ){
+ log(name, msg)
+ }
+ }
+} \ No newline at end of file