在不修改所有接收方法的情况下,在 Akka 中记录所有消息
Log all messages in Akka without modifying all receive methods
我想将收到的所有消息记录到我的 Akka 应用程序中的所有参与者。
有一个配置 akka.actor.debug.receive
将记录发送给该演员的所有消息,如果该演员接收方法是 LoggingReceive
。
根据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
}
}
有没有办法隐式地或通过配置来做到这一点?
据我所知,您应该很容易就能做到这样的事情:
trait LoggingReceiveActor extends Actor{
def receive = LoggingReceive(loggedReceive)
def loggedReceive:Receive
}
class MyActor extends LoggingReceiveActor{
def loggedReceive = {
case _ =>
}
}
任何继承自 LoggingReceiveActor
的 actor 现在必须为 loggingReceive
提供一个 impl,如果您这样做,那么当启用调试日志记录时,此类 actor 将记录收到的消息。
我想将收到的所有消息记录到我的 Akka 应用程序中的所有参与者。
有一个配置 akka.actor.debug.receive
将记录发送给该演员的所有消息,如果该演员接收方法是 LoggingReceive
。
根据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
}
}
有没有办法隐式地或通过配置来做到这一点?
据我所知,您应该很容易就能做到这样的事情:
trait LoggingReceiveActor extends Actor{
def receive = LoggingReceive(loggedReceive)
def loggedReceive:Receive
}
class MyActor extends LoggingReceiveActor{
def loggedReceive = {
case _ =>
}
}
任何继承自 LoggingReceiveActor
的 actor 现在必须为 loggingReceive
提供一个 impl,如果您这样做,那么当启用调试日志记录时,此类 actor 将记录收到的消息。