简体   繁体   中英

Logging sequence calls in WSO2 ESB

I've got a sequence template that does many different calls. Every call logs some parameters / infos.

What I'm trying to achieve is to have some sort of identifier (let's say a unique id) to be passed to all the calls during a sequence execution.

The goal is to trace all the steps of a single execution from the logs, mainly for debugging purposes.

Actually the only idea that came to my mind is to do that programmaticaly, as to say, create a uid at the beginning of the sequence, passing it around, and save it in the log calls. I also tried to mess around with the LogMediator, to make it extract the infos automatically from the external params, but failed (maybe I'm doing it wrong).

Is there any smarter method to do that?

Your requirement can be achieved in various ways. I'm mentioning one of those possibilities.

Since this is an additional method you are going to use for debugging purposes, I think it is better to have a separate log file for this purpose. So first create a new file appender something similar to one given below.

log4j.logger.com.test.CustomDebug=DEBUG, CUSTOM_DEBUG
log4j.additivity.com.test.CustomDebug=false

log4j.appender.CUSTOM_DEBUG = org.apache.log4j.DailyRollingFileAppender
log4j.appender.CUSTOM_DEBUG.File = /home/upul/log/moredebug.log
log4j.appender.CUSTOM_DEBUG.layout = org.apache.log4j.PatternLayout
log4j.appender.CUSTOM_DEBUG.Append = true

Next, create a custom mediator called CustomDebug . Inside mediate() method read parameters from the MessageContext . Next, do some processing (if you have any) and finally, write your log message using log.debug() . This debug message will be written you the new file you created above (in this case it will be /home/upul/log/moredebug.log ).

public class CustomDebug extends AbstractMediator {

    private static final Log log = LogFactory.getLog(CustomDebug.class);

    public boolean mediate(MessageContext mc) {

    }
}

Next, insert CustomDebug class mediator to appropriate places of your sequence template and pass uid as an argument.

As I mentioned previously, this is one of the methods you can use for creating your custom logging. You might need to look at other possibilities as well.

If you need further help regarding this issue please let me know.

Thanks,

Upul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM