Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i1909 - attempting debug log rest api requests #1911

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-parsing" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the new dependency needed for purposes of this PR ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this requires akka.event.slf4j.Slf4jLogger, the akka.event.LoggingAdapter does not log anything without it.

Copy link
Collaborator Author

@pragmaxim pragmaxim Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the configuration section I added should be always present when we are using SLF4J

"org.bitlet" % "weupnp" % "0.1.4",
"commons-net" % "commons-net" % "3.6",

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ bounded-mailbox {
}

akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

actor.mailbox.requirements {
"akka.dispatch.BoundedMessageQueueSemantics" = bounded-mailbox
}
Expand Down
25 changes: 15 additions & 10 deletions src/main/scala/org/ergoplatform/http/ErgoHttpService.scala
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package org.ergoplatform.http

import akka.actor.ActorSystem
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.{HttpRequest, StatusCodes}
import akka.http.scaladsl.server.{ExceptionHandler, RejectionHandler, Route}
import akka.http.scaladsl.server.directives.RouteDirectives
import akka.http.scaladsl.server.directives.{DebuggingDirectives, RouteDirectives}
import scorex.core.api.http.{ApiErrorHandler, ApiRejectionHandler, ApiRoute, CorsHandler}


final case class ErgoHttpService(
apiRoutes: Seq[ApiRoute],
swaggerRoute: SwaggerRoute,
panelRoute: NodePanelRoute
)(implicit val system: ActorSystem) extends CorsHandler {

def rejectionHandler: RejectionHandler = ApiRejectionHandler.rejectionHandler
private def rejectionHandler: RejectionHandler = ApiRejectionHandler.rejectionHandler

private def exceptionHandler: ExceptionHandler = ApiErrorHandler.exceptionHandler

private def requestMethod(req: HttpRequest): String = s"${req.method.value}: ${req.uri}"

def exceptionHandler: ExceptionHandler = ApiErrorHandler.exceptionHandler
private def loggingDirective = DebuggingDirectives.logRequest(requestMethod _)

val compositeRoute: Route =
handleRejections(rejectionHandler) {
handleExceptions(exceptionHandler) {
corsHandler {
apiR ~
apiSpecR ~
swaggerRoute.route ~
panelRoute.route ~
redirectToSwaggerR
loggingDirective {
apiR ~
apiSpecR ~
swaggerRoute.route ~
panelRoute.route ~
redirectToSwaggerR
}
}
}
}
Expand Down