Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log all messages in Akka without modifying all receive methods

I want to log all received messages to all actors in my Akka app. There is a config akka.actor.debug.receive that will log all messages sent to an actor if that actors receive method is a LoggingReceive.

According to http://doc.akka.io/docs/akka/current/additional/faq.html it means wrapping all receive methods with LoggingReceive as in How to log all incoming messages from Akka (Java)

def receive = {
  LoggingReceive {
    case x ⇒ // do something
  }
}

Is there a way to do this implicitly, or by config?

like image 313
mirelon Avatar asked Jan 19 '15 16:01

mirelon


People also ask

What is ActorRef in Akka?

java.io.Serializable. An ActorRef is the identity or address of an Actor instance. It is valid only during the Actor’s lifetime and allows messages to be sent to that Actor instance.

What is DeadLetter in Akka?

Class DeadLetterWhen a message is sent to an Actor that is terminated before receiving the message, it will be sent as a DeadLetter to the ActorSystem's EventStream.

How does Akka handle concurrency?

Akka's approach to handling concurrency is based on the Actor Model. In an actor-based system, everything is an actor, in much the same way that everything is an object in object-oriented design.

Does Akka use log4j?

Project Info. Requires Akka Management and that the application uses Log4j2 as logging backend. Akka Management and akka-management-loglevels-log4j2 can be used with Akka 2.6.


1 Answers

Not that I know of, but you should very easily be able to do something like this:

trait LoggingReceiveActor extends Actor{

  def receive = LoggingReceive(loggedReceive)

  def loggedReceive:Receive
}

class MyActor extends LoggingReceiveActor{

  def loggedReceive = {
    case _ => 
  }
}

Any actor that inherits from LoggingReceiveActor now has to provide an impl for loggingReceive and if you do that, then when debug logging is enabled then this kind of actor will log the messages received.

like image 136
cmbaxter Avatar answered Oct 20 '22 06:10

cmbaxter