2017-10-02 2 views

答えて

0

MDCでは、ログに追加するコンテキストにコンテキストを追加できます。例えば、ログパターン%5p %X{user-id} %m%nで、MDCマップでuser-idを挿入すると、テンプレートのフィールドに値を代入します%X{user-id}

DiagnosticActorLoggingはあなたにmdcへの容易なアクセスを提供し、俳優によって処理された各メッセージのMDCを設定し、クリアの世話をします。 DiagnosticActorLogging特性のaroundReceiveの方法を見てください。それをよりよく理解するためには、

0

それを把握する最も簡単な方法は、DiagnosticActorLogging部をチェックしに行くことです。

/** 
* Scala API: Mix in DiagnosticActorLogging into your Actor to easily obtain a reference to a logger with MDC support, 
* which is available under the name "log". 
* In the example bellow "the one who knocks" will be available under the key "iam" for using it in the logback pattern. 
* 
* {{{ 
* class MyActor extends Actor with DiagnosticActorLogging { 
* 
* override def mdc(currentMessage: Any): MDC = { 
*  Map("iam", "the one who knocks") 
* } 
* 
* def receive = { 
*  case "pigdog" => log.info("We've got yet another pigdog on our hands") 
* } 
* } 
* }}} 
*/ 
trait DiagnosticActorLogging extends Actor { 
    import akka.event.Logging._ 
    val log = akka.event.Logging(this) 
    def mdc(currentMessage: Any): MDC = emptyMDC 

    override protected[akka] def aroundReceive(receive: Actor.Receive, msg: Any): Unit = try { 
    log.mdc(mdc(msg)) 
    super.aroundReceive(receive, msg) 
    } finally { 
    log.clearMDC() 
    } 
} 

基本的には、暗黙的にすべての混乱なしに俳優のすべてのログコールにロギングデータのいくつかの共有作品を関連付けることができますそれらを明示的に追加する。アプリケーションによっては、ホスト名、リクエストID、クライアントID、jarバージョン、ビルド日付、エンドポイントなどに便利です。

関連する問題