Skip to content

Instantly share code, notes, and snippets.

@patriknw
Created December 20, 2013 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patriknw/8054187 to your computer and use it in GitHub Desktop.
Save patriknw/8054187 to your computer and use it in GitHub Desktop.
Example of a custom LoggingReceive
import akka.actor.Actor.Receive
import akka.actor.ActorContext
import akka.actor.ActorLogging
import akka.actor.Actor
import akka.event.LoggingAdapter
object MyLoggingReceive {
def apply(log: LoggingAdapter)(r: Receive)(implicit context: ActorContext): Receive = r match {
case _: MyLoggingReceive ⇒ r
case _ ⇒
if (context.system.settings.config.getBoolean("myloggingreceive")) new MyLoggingReceive(log, r) else r
}
}
class MyLoggingReceive(log: LoggingAdapter, r: Receive) extends Receive {
def isDefinedAt(o: Any): Boolean = {
val handled = r.isDefinedAt(o)
log.info("received {} message {}", if (handled) "handled" else "unhandled", o)
handled
}
def apply(o: Any): Unit = r(o)
}
class MyActor extends Actor with ActorLogging {
def receive = MyLoggingReceive(log) {
case msg ⇒
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment