In my code, I have 2 methods processInbound()
and processOutbound()
. I am trying to use AOP to load MDC data so that in the logs I can identify the journey.
My code is working as I can see the desired journey details in the log.
Following is my method
public void processInboundData() {
//Do get journey details in the following info
log.info("In the method processInboundData");
//Method i call to process the data
//Do get journey details in all info's defined in fetchAndSaveData method
ddlDataService.fetchAndSaveData();
//Don't get journey=Inbound in the following info
log.info("After done");
}
This is the Aspect
@Around("execution(*package.processInboundData(..))")
public Object processInboundData(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
MDC.put(Journey , "Inbound");
try {
// invoke the method.
return proceedingJoinPoint.proceed();
} finally {
MDC.clear();
}
}
The problem that I can see is that in the logs I do get the log lines with the correct journey name in the following lines:
processInboundData - [journey=Inbound] - [] In the method processInboundData
I also get "[journey=Inbound]" in all the info lines that are there in the called method "fetchAndSaveData"
But I don't get "[journey=Inbound]" in the line just after the method call returns, so the logline shows up as with the missing "[journey=Inbound]".
processInboundData - - [] After done
Not sure why is this happening
Any help would be greatly appreciated
processInboundData - - [] After done
but in your code insideprocessInboundData()
method you are loggingAfter method call
. Is this a typo or isAfter done
logged somewhere else?