Thing which seemed very Thingish inside you is quite different when it gets out into the open and has other people looking at it

Friday, August 3, 2012

How to create service specific logs for WSO2 ESB


In this post I am going to talk how you can create differant log files depending on your proxy service using WSO2 ESB. Lets say you have a proxy service deployed in ESB and you need to filter out the logs generated by that given proxy service. You can  do this in three easy steps using wso2 logging-mgt feature.

Step 1 - Creating a proxy service with LogMediator


In order to try this out you need to create a proxy service which uses log-mediator so we can easily generate logs comming from that proxy service.

So this is my proxy service


<proxy xmlns="http://ws.apache.org/ns/synapse" name="MyProxyService" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">

  <target>
     <inSequence>
        <log level="full">
           <property name="MESSAGE" value="****************Inside in sequance*********************" />
        </log>
     </inSequence>
     <outSequence>
        <log level="full">
           <property name="Message2" value="************Inside out sequance ************************" />
        </log>
        <send />
     </outSequence>
     <endpoint>
     </endpoint>
  </target>
</proxy>

Step2 - Adding Service Level log appender to send logs to differant log file location


WSo2 logging-mgt feature use standard apache log4j framework therefore, you need to change log4j properties in order to create appenders. We will create a new appender call MY_PROXY_APPENDER


log4j.additivity.MY_PROXY_APPENDER=false
log4j.appender.MY_PROXY_APPENDER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.MY_PROXY_APPENDER.File=${carbon.home}/repository/logs/${instance.log}/wso2-esb-my-proxy${instance.log}.log
log4j.appender.MY_PROXY_APPENDER.Append=true
log4j.appender.MY_PROXY_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.MY_PROXY_APPENDER.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%


Here we are defining what kind of an appender, we will use DailyRollingFileAppender you can change the appender type depending on your need such as DBAppender,SyslogAppender etc And also you need to give appender properties like file location, which patternlayout you need to use and the log pattern you need. ALl these are configurable depending on your need.

Step 3 - Adding your logger in the root logger.


You need to aknowlege the newly created Appender in log4j.logger to map MyProxyServic to the SERVICE_LOGGER. The logger will be under Service_Logger so you need to specify your appender as shown below.

 log4j.category.SERVICE_LOGGER.MyProxyService =INFO, PROXY_APPENDER


Thats it!! you can go to {CARBON_HOME}/repository/logs to view your newly created proxy service specific log file!!!!

No comments:

Post a Comment