我有以下演员,当谈到演员
时,我怎么能强制它所有的消息呢?class NewsActor @Inject()(wsClient: WSClient, appConfig: AppConfig)
(implicit ec: ExecutionContext) extends Actor {
import ArticleJsonParser._
override def receive = LoggingReceive {
case RequestNews =>
val futureArticles = wsClient.url(News.TECH_URL)
.withQueryString("source" -> News.SOURCE, "apiKey" -> appConfig.newsApiKey)
.get() map { response =>
(Json.parse(response.body) \ "articles").as[Seq[Article]]
}
pipe(futureArticles).to(sender())
case _ => Logger.error("NewsActor message not supported failed")
}
}
正如在此处的akka文档中所述:http://doc.akka.io/docs/akka/current/scala/logging.html并在此处播放文档:https://www.playframework.com/documentation/2.5.x/SettingsLogger 我将它混合起来并添加以下application.conf:
akka {
loglevel = "DEBUG"
loggers = ["akka.event.slf4j.Slf4jLogger"]
actor {
debug {
# enable function of LoggingReceive, which is to log any received message at
# DEBUG level
receive = on
}
}
}
并遵循logback.xml
<!--
~ Copyright (C) 2009-2016 Lightbend Inc. <https://www.lightbend.com>
-->
<!-- The default logback configuration that Play uses in dev mode if no other configuration is provided -->
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>
<logger name="play" level="DEBUG" />
<logger name="application" level="DEBUG" />
<!-- Set logging for all Akka library classes to INFO -->
<logger name="akka" level="DEBUG" />
<!-- Set a specific actor to DEBUG -->
<!--<logger name="actors.*" level="DEBUG" />-->
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>
目前在应用程序控制台中我只看到
[info] a.e.s.Slf4jLogger - Slf4jLogger started
[debug] a.e.EventStream - logger log1-Slf4jLogger started
[debug] a.e.EventStream - Default Loggers started
[debug] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
[info] play.api.Play - Application started (Dev)
更新:
当我用loggers = ["akka.event.slf4j.Slf4jLogger"]
替换loggers = ["akka.event.Logging$DefaultLogger"]
时,它开始打印消息,但它不是通过播放记录器打印出来的。
经度:
[debug] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
[DEBUG] [11/04/2016 13:03:19.743] [application-akka.actor.default-dispatcher-4] [EventStream(akka://application)] logger log1-Logging$DefaultLogger started
[DEBUG] [11/04/2016 13:03:19.743] [application-akka.actor.default-dispatcher-4] [EventStream(akka://application)] Default Loggers started
[info] play.api.Play - Application started (Dev)
[DEBUG] [11/04/2016 13:03:19.863] [application-akka.actor.default-dispatcher-2] [akka://application/user/news-actor] received handled message RequestNews from Actor[akka://application/temp/$a]
虽然它也应该打印出actor收到的消息,但我的配置有什么问题?