Skip to content

Instantly share code, notes, and snippets.

@zygm0nt
Created March 11, 2014 08:31
Show Gist options
  • Save zygm0nt/9481663 to your computer and use it in GitHub Desktop.
Save zygm0nt/9481663 to your computer and use it in GitHub Desktop.
scala spray route debugging
trait AbcService with UnhandledRouteDebug {
override def receive: Actor.Receive = runRoute(logRequestResponse(myLog _) {
staticRoute ~ internalRoutes ~ routes
})
}
trait UnhandledRouteDebug {
def myLog(request: HttpRequest): Any => Option[LogEntry] = {
case x: HttpResponse => {
println (s"Normal: $request")
createLogEntry(request, x.status + " " + x.toString())
}
case Rejected(rejections) => {
println (s"Rejection: $request")
createLogEntry(request, " Rejection " + rejections.toString())
}
case x => {
println (s"other: $request")
createLogEntry(request, x.toString())
}
}
def createLogEntry(request: HttpRequest, text: String): Some[LogEntry] = {
Some(LogEntry("#### Request " + request + " => " + text, DebugLevel))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment