I have struggled a lot with the same challenge. The MDC feature of the 
logging frameworks need a little more "manual" intervention when operating 
in an asynchronous runtime like Akka. MDC is tightly coupled to a thread, 
but communication with and between Actors happen in different threads. 
Hence, the MDC is not propagated automatically when sending messages 
between your actors. Basically, you need to pass the context you wish to 
log along with the messages in your system. So if you want to trace a 
requestId in a conversation between your actors, you need to pass the 
requestId along in the message, and then put it back in the MDC in the 
receiving actor. 

Regards,

Nils-Helge Garli Hegvik

On Thursday, May 7, 2015 at 10:27:59 AM UTC+2, byse...@gmail.com wrote:
>
> Hi √,
>>
>> I want to have MDC logging so I can organize my logs, for example 
>> according to requestId. 
>>
>> I am tried out the example in 
>> http://doc.akka.io/docs/akka/2.3.10/scala/logging.html#MDC_values_defined_by_the_application
>> .
>>
>> It works fine for a single actor, but If I'm sending a message to another 
>> Actor, the MDC values are not log on the other Actors.
>>
>> class RequestHandler() extends Actor with 
>> akka.actor.DiagnosticActorLogging{
>>
>>    override def mdc(currentMessage: Any): MDC = {
>>      currentMessage match {
>>        case req: TypeA => Map("requestId" -> req.id)
>>        case _ => Map()
>>      }
>>    }
>>
>>    def receive: Receive = {
>>       case req: TypeA =>
>>          log.debug("RECEIVE req typeA")                 //logged with 
>> correct "[requestId -> someRandom]"
>>          val actorA = context.ActorOf(ActorA.props)
>>          actorA ! req                                   //logs in actorA 
>> are do not have value on requestId (how to log them?)
>>    }
>> }
>>
>> class ActorA() extends Actor with akka.actor.DiagnosticActorLogging {...} 
>> //logs of helperActors called by ActorA are not also logged with correct 
>> requestId (how to log them?)
>>
>> Is it possible with AKKA MDC to log all codeLogs (including logs from 
>> dependency libs) for a certain requestId with correct MDC map values?
>>
>
>    I also set akka logger to sl4fj on my application.conf
>
> akka {
>   loggers = ["akka.event.slf4j.Slf4jLogger"]
>      logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
>
>  
>
>>
>> On Monday, April 27, 2015 at 3:30:47 PM UTC+8, √ wrote:
>> Hi Anindita,
>>
>> It would be great for us to know what is lacking in the MDC sections of 
>> the Akka Logging documentation,
>> please don't hesitate to contribute.
>>
>> Thanks!
>>
>> On Mon, Apr 27, 2015 at 8:09 AM, Anindita Ghatak <anindi...@gmail.com> 
>> wrote:
>> Hi,
>> How can I use Akka with org.apache.log4j.MDC ?
>>
>> Thanks & Regards,
>> Anindita
>> -- 
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to akka-user+...@googlegroups.com.
>> To post to this group, send email to akka...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/akka-user.
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> -- 
>> Cheers,
>> √
>>
> 

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to