Skip to content

Instantly share code, notes, and snippets.

@RichardBradley
Last active August 29, 2015 14:16
Show Gist options
  • Save RichardBradley/f7b1b7c3358779e3559d to your computer and use it in GitHub Desktop.
Save RichardBradley/f7b1b7c3358779e3559d to your computer and use it in GitHub Desktop.
Akka drops error logs on ActorSystem guardian death
.idea
myApp.log
target
package akka
import akka.actor._
import com.typesafe.config.{ConfigValueFactory, ConfigFactory, Config}
import scala.collection.JavaConversions._
object Application {
def main(args: Array[String]): Unit = {
val system = ActorSystem("test", config)
println("Wait a bit for everything to settle down")
Thread.sleep(500)
println("stuff the logger's mailbox")
(1 to 10000).foreach { i =>
system.log.debug("mailbox stuffing " + i)
}
println("simulate a failed assertion somewhere in the ActorSystem")
system.actorOf(Props(new FailingAssertionActor())) ! "message"
println("Wait a bit for everything to settle down, and things to flush")
Thread.sleep(500)
assert(system.isTerminated)
}
class FailingAssertionActor
extends Actor
{
override def receive: Receive = {
case x =>
assert(false, "it is important that this gets logged")
}
}
val config = {
System.setProperty("logback.configurationFile", "logback.xml")
ConfigFactory.load()
.withValue("akka.loggers", ConfigValueFactory.fromIterable(List("akka.event.slf4j.Slf4jLogger")))
.withValue("akka.loglevel", ConfigValueFactory.fromAnyRef("DEBUG"))
}
}
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-experimental" % "1.0-M3",
"com.typesafe.akka" %% "akka-http-testkit-experimental" % "1.0-M3" % "test",
"com.typesafe.akka" %% "akka-slf4j" % "2.3.7",
"ch.qos.logback" % "logback-classic" % "1.1.2")
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>myApp.log</file>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<root level="all">
<appender-ref ref="FILE" />
</root>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment