私はWebサービスを作成しており、しばしばHTTPS経由でメッセージを送信しています。関数を使うよりもScalaで情報を記録する良い方法はありますか?
val response = sendJson(JsonUtil.getTextMessageJson("Sorry I don't understand what day you want. You can say " + "things like \"tomorrow\" or \"next Friday\""))
私はonCompleteの{でこのコールをたどる}、そして得られた成功または失敗を扱うが、私はそう頻繁にこれを行うので、私はヘルパークラスで単純な関数を記述することができ
:
def logSendResult(response: Future[WSResponse])(implicit userId: String): Unit = {
response onComplete {
case Success(res) => Logger.info("Message to " + userId + " sent successfully with " +
"response code: " + res.status)
case Failure(exception) => Logger.info("Message to " + userId + " failed with " +
"exception: " + exception.getMessage)
}
}
私はその後を呼んで:これは正常に動作しているが、私はでした
LogUtils.logSendResult(response)
もっと良い方法があるのだろうか?
私はPlayを使用しませんが、すばやくGoogle検索するとHttpFiltersのように見えます:https://www.playframework.com/documentation/2.5.x/ScalaHttpFilters –