Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging all messages sent to an Akka TestKit TestProbe

I'm trying to log all messages received by a TestKit TestProbe, which is proving to be somewhat difficult. I'm aware of the Actor Logging section in the docs where it says one should use the debug.receive option in combination with a LogginReceive block. This however doesn't work when I'm not in control of the actor's implementation.

The only idea I had was subclassing akka.testkit.TestActor to use a LoggingReceive and then subclass TestKit to make it create instances of my TestActor subclass instead, but that didn't work because most functionality there is private to the akka namespace (and for good reason, I suppose).

like image 202
fresskoma Avatar asked Nov 16 '12 16:11

fresskoma


1 Answers

There is a (probably surprisingly) simple answer:

probe.setAutoPilot(new TestActor.AutoPilot {
  def run(sender: ActorRef, msg: Any) = {
    log.debug("whatever")
    this
  }
})
like image 150
Roland Kuhn Avatar answered Sep 30 '22 09:09

Roland Kuhn