diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-03-28 22:12:53 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 18:03:21 +0100 |
commit | 8d91a5a9141393e6c738d8624f7fe5d1bbdb28f9 (patch) | |
tree | a51880194eb31b00611be8dd6d713d3072bd2f2f /Scala/recfun/project/RecordingLogger.scala | |
parent | 6b137fb0ee01b203f4008ab85ad88a1c1aec3cbe (diff) | |
download | coursera-8d91a5a9141393e6c738d8624f7fe5d1bbdb28f9.zip coursera-8d91a5a9141393e6c738d8624f7fe5d1bbdb28f9.tar.gz |
Scala : add recfun
Diffstat (limited to 'Scala/recfun/project/RecordingLogger.scala')
-rw-r--r-- | Scala/recfun/project/RecordingLogger.scala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Scala/recfun/project/RecordingLogger.scala b/Scala/recfun/project/RecordingLogger.scala new file mode 100644 index 0000000..b886768 --- /dev/null +++ b/Scala/recfun/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) = () +} |