aboutsummaryrefslogtreecommitdiff
path: root/stage1/logger.scala
blob: 373a9542d97680f4aec509b3635c9c1710aba016 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
package cbt

/**
 * This represents a logger with namespaces that can  be enabled or disabled as needed. The
 * namespaces are defined using {{enabledLoggers}}. Possible values are defined in the subobject
 * "names".
 *
 * We can replace this with something more sophisticated eventually.
 */
case class Logger(enabledLoggers: Set[String], start: Long) {
  def this(enabledLoggers: Option[String], start: Long) = {
    this(
      enabledLoggers.toVector.flatMap( _.split(",") ).toSet,
      start
    )
  }

  val disabledLoggers: Set[String] = enabledLoggers.filter(_.startsWith("-")).map(_.drop(1))

  def log(name: String, msg: => String) = {
    if(
      (
        (enabledLoggers contains name)
        || (enabledLoggers contains "all")
      ) && !(disabledLoggers contains name)
    ){
      logUnguarded(name, msg)
    }
  }

  def showInvocation(method: String, args: Any) = method ++ "( " ++ args.toString ++ " )"

  final def stage1(msg: => String) = log(names.stage1, msg)
  final def stage2(msg: => String) = log(names.stage2, msg)
  final def loop(msg: => String) = log(names.loop, msg)
  final def task(msg: => String) = log(names.task, msg)
  final def composition(msg: => String) = log(names.composition, msg)
  final def resolver(msg: => String) = log(names.resolver, msg)
  final def lib(msg: => String) = log(names.lib, msg)
  final def test(msg: => String) = log(names.test, msg)
  final def git(msg: => String) = log(names.git, msg)
  final def pom(msg: => String) = log(names.pom, msg)
  final def dynamic(msg: => String) = log(names.dynamic, msg)
  final def run(msg: => String) = log(names.run, msg)
  final def transientCache(msg: => String) = log(names.transientCache, 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"
    val test = "test"
    val pom = "pom"
    val run = "run"
    val git = "git"
    val dynamic = "dynamic"
    val transientCache = "transientCache"
  }

  private def logUnguarded(name: String, msg: => String) = {
    val timeTaken = ((System.currentTimeMillis.toDouble - start) / 1000).toString
    System.err.println( s"[$timeTaken][$name] $msg" )
  }
}