spray.io调试指令

时间:2015-07-28 13:55:11

标签: scala spray spray-dsl

我正在玩spray.io并且我无法使用调试指令logRequestResponse工作 - 我没有在日志中看到任何输出。

 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
                     }                    
                   }
              }
            }
            }
      }
    }
  }

我在这里遗漏了什么吗? 我是否需要在喷涂配置中的某个地方启用全局调试?我尝试了不同的地方,但没有一个按预期工作

1 个答案:

答案 0 :(得分: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".