AnsweredAssumed Answered

MDC Logging from methods called with Spring expression

Question asked by jritter on Sep 13, 2016
Latest reply on Oct 19, 2016 by mmalczewski
Hi everybody

I am wondering whether it is possible to log the Activiti MDC Attributes in Log messages which are generated by our own code which is called by a Service Task. I've followed the instructions in the Activiti User Guide (http://www.activiti.org/userguide/#MDC), and the keys are showing up in the logfile. The value of these 3 attributes always seems to be empty though.

Here an example:

18:20:39,796 [pool-13-thread-1] INFO  my.package.MyClass ProcessDefinitionId= executionId= mdcProcessInstanceID= mdcBusinessKey=  - endEvent started: End


my Appender configuration looks as follows:

log4j.appender.CA.layout.ConversionPattern= %d{HH:mm:ss,SSS} [%t] %-5p %c{1.} ProcessDefinitionId=%X{mdcProcessDefinitionID} executionId=%X{mdcExecutionId} mdcProcessInstanceID=%X{mdcProcessInstanceID} mdcBusinessKey=%X{mdcBusinessKey} %x - %m%n

In the code which is called by the Service Task by an expression or delegate expression, I do the following:

logger.info("my Message")


The logger instances is obtained by the following call:


static final Log logger = LogFactory.getLog(MyClass.class.getName());


What do I have to do so that these MDC attributes show up in my custom log messages? Do I miss something?

Any help is appreciated.

Thanks and regards,
Juerg

Outcomes