In Scala you can wrap the receive function with a LoggingReceive. How do you achieve the same from the Java API?
def receive = {
LoggingReceive {
case x ⇒ // do something
}
}
The Scala API has the LoggingReceive
decorator because a partial function literal makes it awkward to express something to be done in all cases (like this logging).
In Java you don’t have this problem because your onReceive
method is always called, and you can put a logging statement at the top to see all messages which are received by the actor. As an added bonus you get to decide at which level to log them ;-)
If you want to make your logging conditional on the config setting akka.actor.debug.receive
(just as for Scala), then you can say for example
if (getContext().system().settings().AddLoggingReceive())
log.debug("received message of type {}", msg.getClass());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With