summaryrefslogtreecommitdiffstats
path: root/Scala/streams/project/RecordingLogger.scala
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-05-17 16:43:31 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-10 18:03:25 +0100
commitd8d74ed55984d2ae39cbdb965dd42bba984735a9 (patch)
tree592cafc584e08ce997378f69f86ebf4d80d44674 /Scala/streams/project/RecordingLogger.scala
parent12a9fca3908dc0b9bf7d51abd37db542b4600bb1 (diff)
downloadcoursera-d8d74ed55984d2ae39cbdb965dd42bba984735a9.zip
coursera-d8d74ed55984d2ae39cbdb965dd42bba984735a9.tar.gz
Scala : add streams assignment
Diffstat (limited to 'Scala/streams/project/RecordingLogger.scala')
-rw-r--r--Scala/streams/project/RecordingLogger.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/Scala/streams/project/RecordingLogger.scala b/Scala/streams/project/RecordingLogger.scala
new file mode 100644
index 0000000..b886768
--- /dev/null
+++ b/Scala/streams/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) = ()
+}