diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-04-03 22:06:18 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 18:03:22 +0100 |
commit | 545c03ac4981737594d7638b7a925d1881a74cdc (patch) | |
tree | 15b6173c9ce1cc64d67d9bc1f90cd7301c2e7442 /Scala/funsets/project/RecordingLogger.scala | |
parent | f885b79568a221f9d1cf8edc612f69bec5aad1cc (diff) | |
download | coursera-545c03ac4981737594d7638b7a925d1881a74cdc.zip coursera-545c03ac4981737594d7638b7a925d1881a74cdc.tar.gz |
Scala : add funset
Diffstat (limited to 'Scala/funsets/project/RecordingLogger.scala')
-rw-r--r-- | Scala/funsets/project/RecordingLogger.scala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Scala/funsets/project/RecordingLogger.scala b/Scala/funsets/project/RecordingLogger.scala new file mode 100644 index 0000000..b886768 --- /dev/null +++ b/Scala/funsets/project/RecordingLogger.scala @@ -0,0 +1,35 @@ +import sbt._ +import collection.mutable.ListBuffer + +/** + * Logger to capture compiler output, test output + */ + +object RecordingLogger extends Logger { + private val buffer = ListBuffer[String]() + + def hasErrors = buffer.nonEmpty + + def readAndClear() = { + val res = buffer.mkString("\n") + buffer.clear() + res + } + + def clear() { + buffer.clear() + } + + def log(level: Level.Value, message: => String) = + if (level == Level.Error) { + buffer += message + } + + // we don't log success here + def success(message: => String) = () + + // invoked when a task throws an exception. invoked late, when the exception is logged, i.e. + // just before returning to the prompt. therefore we do nothing: storing the exception in the + // buffer would happen *after* the `handleFailure` reads the buffer. + def trace(t: => Throwable) = () +} |