Skip to content

Instantly share code, notes, and snippets.

@ppurang
Forked from patriknw/MyLoggingReceive.scala
Created January 29, 2014 01:41
Show Gist options
  • Save ppurang/8680172 to your computer and use it in GitHub Desktop.
Save ppurang/8680172 to your computer and use it in GitHub Desktop.
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