1

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

jaksky
  • 3,305
  • 4
  • 35
  • 68

1 Answers1

0

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".

Jaime Agudo
  • 8,076
  • 4
  • 30
  • 35
  • That all has already been checked. Logging otherwise works fine. Root logger set on Debug level. I was more concerned with directive usage – jaksky Jul 28 '15 at 16:21
  • Why don't you switch the order and place the `DebuggingDirectives.logRequestResponse("city-trans", Logging.InfoLevel) ` just before the `post` ? Perhaps the `authenticate` is failing before – Jaime Agudo Jul 28 '15 at 16:26
  • Tried all positions. More over the route successfully completes request – jaksky Jul 28 '15 at 16:29
  • I don't see the required implicit `LogginContext`, I guess it's there as you can run it but mind the note _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"._ – Jaime Agudo Jul 28 '15 at 16:38
  • Working [example](https://github.com/knoldus/spray-akka-starter/blob/master/src/main/scala/com/knoldus/hub/StartHub.scala) – Jaime Agudo Jul 28 '15 at 16:45
  • I am using HttpService runRute on tilde concatenated routes, so I suppose that should be available. Any idea how to validate that? – jaksky Jul 28 '15 at 16:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84492/discussion-between-james-sharp-and-jaksky). – Jaime Agudo Jul 28 '15 at 17:06
  • Implicits didn't get propagated. Thanks for helping me out! – jaksky Jul 29 '15 at 10:27
  • I guess you finally saw the chat :) I felt this pain before, it's hard to keep the track and figure out the implicits visibility when you mix traits etc. – Jaime Agudo Jul 29 '15 at 21:38