diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-11-09 16:13:44 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-11-09 16:13:44 +0000 |
commit | 398e777ecdad0d61d5f78da1c6b6f3c8d5a9dee1 (patch) | |
tree | ca1dd41fe5a33f277b1516f7aa211ee61ba5101d /src | |
parent | f7e5d9d0af7a5af7b7caabef75dcea0e2b27971e (diff) | |
download | scala-398e777ecdad0d61d5f78da1c6b6f3c8d5a9dee1.tar.gz scala-398e777ecdad0d61d5f78da1c6b6f3c8d5a9dee1.tar.bz2 scala-398e777ecdad0d61d5f78da1c6b6f3c8d5a9dee1.zip |
Added exception logging.
Diffstat (limited to 'src')
-rw-r--r-- | src/actors/scala/actors/Reaction.scala | 26 | ||||
-rw-r--r-- | src/actors/scala/actors/Scheduler.scala | 7 | ||||
-rw-r--r-- | src/actors/scala/actors/TimerThread.scala | 18 |
3 files changed, 44 insertions, 7 deletions
diff --git a/src/actors/scala/actors/Reaction.scala b/src/actors/scala/actors/Reaction.scala index ee25c73e3a..5b7c5e0f66 100644 --- a/src/actors/scala/actors/Reaction.scala +++ b/src/actors/scala/actors/Reaction.scala @@ -11,10 +11,12 @@ package scala.actors - import java.lang.Runnable import java.lang.InterruptedException +import java.util.logging.Logger +import java.util.logging.Level + /** * The abstract class <code>Reaction</code> associates an instance * of an <code>Actor</code> with a @@ -27,6 +29,19 @@ import java.lang.InterruptedException */ private[actors] abstract class Reaction extends Runnable { def actor: Actor + + def log(t: Throwable): unit = { + Debug.info("logging "+t) + val logger = Logger.getLogger("Scheduler") + val buf = new StringBuffer + buf.append("Exception caught by task:\n") + buf.append(t.toString()+"\n") + val trace = t.getStackTrace() + for (val elem <- trace) { + buf.append(elem.toString() + "\n") + } + logger.log(Level.FINE, buf.toString()) + } } /** @@ -55,15 +70,14 @@ private[actors] class StartTask(a: Actor) extends Reaction { } catch { case ie: InterruptedException => { - // TODO: use Debug - ie.printStackTrace() + log(ie) a.exitLinked() } case d: SuspendActorException => { // do nothing (continuation is already saved) } case t: Throwable => { - t.printStackTrace() + log(t) a.exit(t.toString()) } } @@ -102,14 +116,14 @@ private[actors] class ActorTask(a: Actor, } catch { case ie: InterruptedException => { - ie.printStackTrace() + log(ie) a.exitLinked() } case d: SuspendActorException => { // do nothing (continuation is already saved) } case t: Throwable => { - t.printStackTrace() + log(t) a.exit(t.toString()) } } diff --git a/src/actors/scala/actors/Scheduler.scala b/src/actors/scala/actors/Scheduler.scala index 6d6345d11c..50d7a2db39 100644 --- a/src/actors/scala/actors/Scheduler.scala +++ b/src/actors/scala/actors/Scheduler.scala @@ -14,6 +14,10 @@ package scala.actors import java.lang.{Runnable, Thread} import java.lang.InterruptedException +import java.util.logging.Logger +import java.util.logging.FileHandler +import java.util.logging.Level + import compat.Platform import scala.collection.mutable.{ArrayBuffer, Buffer, HashMap, Queue, Stack} @@ -29,6 +33,9 @@ object Scheduler { private var sched: IScheduler = //new SpareWorkerScheduler { + val logger = Logger.getLogger("Scheduler") + logger.addHandler(new FileHandler("sched.log")) + logger.setLevel(Level.FINE) val s = new TickedScheduler s.start() s diff --git a/src/actors/scala/actors/TimerThread.scala b/src/actors/scala/actors/TimerThread.scala index c394b6bdd0..e4588d4a12 100644 --- a/src/actors/scala/actors/TimerThread.scala +++ b/src/actors/scala/actors/TimerThread.scala @@ -15,6 +15,9 @@ package scala.actors import java.lang.{Runnable, Thread} import java.lang.InterruptedException +import java.util.logging.Logger +import java.util.logging.Level + /** * This class allows the (local) sending of a message to an actor after * a timeout. Used by the library to build <code>receiveWithin(time: long)</code>. @@ -53,6 +56,19 @@ object TimerThread extends AnyRef with Runnable { } } + def log(t: Throwable): unit = { + Debug.info("logging "+t) + val logger = Logger.getLogger("Scheduler") + val buf = new StringBuffer + buf.append("Exception caught by task:\n") + buf.append(t.toString()+"\n") + val trace = t.getStackTrace() + for (val elem <- trace) { + buf.append(elem.toString() + "\n") + } + logger.log(Level.FINE, buf.toString()) + } + override def run = { try { while(true) { @@ -61,7 +77,7 @@ object TimerThread extends AnyRef with Runnable { val sleepTime = dequeueLateAndGetSleepTime if (lateList.isEmpty) wait(sleepTime) } catch { - case t: Throwable => { t.printStackTrace(); throw t } + case t: Throwable => { log(t); throw t } } } |