scalasprayspray-dsl

spray.io debugging directives


I am playing around with spray.io and I am not able to make spray debugging directives logRequestResponse work - I don't see any output in the log.

 val route: Route = {
    pathPrefix("city") {
      pathPrefix("v1") {
        path("transaction" / Segment / Segment) {
          (siteId: String, transactionId: String) =>
            post {
              authenticate(BasicAuth(UserPasswordAuthenticator _, realm = "bd cinema import api")) {
                user =>
                   DebuggingDirectives.logRequestResponse("city-trans", Logging.InfoLevel) {                         
                     val resp = "Hello"
                     complete {
                       resp
                     }                    
                   }
              }
            }
            }
      }
    }
  }

Am I missing something here? Do I need to enable debugging in global somewhere in spray configuration? I tried different places and none of them worked as expected


Solution

  • Check you have sensible values at your application.conf and logback.xml as these sample files on the Spray project

    Pay attention at application.conf akka.loglevel=INFO

    akka {
      log-config-on-start = on
      loglevel = "INFO"
      actor.timeoutsecs = 2
      loggers = ["akka.event.slf4j.Slf4jLogger"]
    }
    

    A minimum logback.xml to display logs on stdout.

    <configuration>
        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
            <target>System.out</target>
            <encoder>
                <pattern>[%d{dd/MM/yyyy HH:mm:ss.SSS}] [%level] [%thread] %logger{36} - %msg %n</pattern>
                <!--<pattern>%X{akkaTimestamp} %-5level[%thread] %logger{0} - %msg%n</pattern>-->
            </encoder>
        </appender>
        <!--   <logger name="com.vegatic" level="DEBUG"/> -->
        <root level="DEBUG">
            <appender-ref ref="CONSOLE"/>
        </root>
    </configuration>
    

    Usual suspects are logger's name attributes not matching the Scala namespaces or not verbose enough which have been commented on the example above for clarity

    Docs link for LoggingContext

    A LoggingAdapter that can always be supplied implicitly. If an implicit ActorSystem the created LoggingContext forwards to the log of the system. If an implicit ActorContext is in scope the created LoggingContext uses the context's ActorRef as a log source. Otherwise, i.e. if neither an ActorSystem nor an ActorContext is implicitly available, the created LoggingContext will forward to NoLogging, i.e. "/dev/null".